DROP TABLE statement
How DROP TABLE and DROP TEMPORARY TABLE work, with the foreign-key and view rules.
DROP TABLE removes one or more tables with their rows, indexes and triggers.
Syntax#
DROP [TEMPORARY] TABLE [IF EXISTS] [db_name.]tbl_name [, [db_name.]tbl_name] ...Arguments#
| Name | Meaning | Default |
|---|---|---|
TEMPORARY | Drop only temporary tables of the session. | off |
IF EXISTS | A table that does not exist is not an error (a warning is given). | off |
Remarks#
- A temporary table hides a base table of the same name;
DROP TABLEdrops the temporary one first. - A table that other tables refer to by a foreign key cannot be dropped (error 3730) unless
foreign_key_checksis 0. DROP TABLEon a view gives error 1051; useDROP VIEW.- The triggers of the table go with it.
- Privileges:
DROPon the table (not asked for temporary tables). - The statement cannot be rolled back.
RESTRICTandCASCADEafter the names are not in the grammar of this statement.
Examples#
DROP TABLE IF EXISTS nosuch, t2;
DROP TEMPORARY TABLE IF EXISTS base;
DROP TABLE copy1, copy2;