SQL reference (MySQL and MariaDB dialects)

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#

SQL
DROP [TEMPORARY] TABLE [IF EXISTS] [db_name.]tbl_name [, [db_name.]tbl_name] ...

Arguments#

NameMeaningDefault
TEMPORARYDrop only temporary tables of the session.off
IF EXISTSA 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 TABLE drops the temporary one first.
  • A table that other tables refer to by a foreign key cannot be dropped (error 3730) unless foreign_key_checks is 0.
  • DROP TABLE on a view gives error 1051; use DROP VIEW.
  • The triggers of the table go with it.
  • Privileges: DROP on the table (not asked for temporary tables).
  • The statement cannot be rolled back.
  • RESTRICT and CASCADE after the names are not in the grammar of this statement.

Examples#

SQL
DROP TABLE IF EXISTS nosuch, t2;
DROP TEMPORARY TABLE IF EXISTS base;
DROP TABLE copy1, copy2;

See also#