Important

You are viewing the documentation of an older version of the TiDB database (TiDB v5.4).

It is recommended that you use the latest LTS version of the TiDB database.

DROP TABLE

This statement drops a table from the currently selected database. An error is returned if the table does not exist, unless the IF EXISTS modifier is used.

Synopsis

DropTableStmt
DROPOptTemporaryTableOrTablesIfExistsTableNameListRestrictOrCascadeOpt
OptTemporary
TEMPORARYGLOBALTEMPORARY
TableOrTables
TABLETABLES
TableNameList
TableName,

Drop temporary tables

You can use the following syntax to drop ordinary tables and temporary tables:

  • Use DROP TEMPORARY TABLE to drop local temporary tables.
  • Use DROP GLOBAL TEMPORARY TABLE to drop global temporary tables.
  • Use DROP TABLE to drop ordinary tables or temporary tables.

Examples

mysql> CREATE TABLE t1 (a INT);
Query OK, 0 rows affected (0.11 sec)

mysql> DROP TABLE t1;
Query OK, 0 rows affected (0.22 sec)

mysql> DROP TABLE table_not_exists;
ERROR 1051 (42S02): Unknown table 'test.table_not_exists'
mysql> DROP TABLE IF EXISTS table_not_exists;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE VIEW v1 AS SELECT 1;
Query OK, 0 rows affected (0.10 sec)

mysql> DROP TABLE v1;
Query OK, 0 rows affected (0.23 sec)

MySQL compatibility

  • Dropping a table with IF EXISTS does not return a warning when attempting to drop a table that does not exist. Issue #7867
  • Currently RESTRICT and CASCADE are only supported syntactically.

See also

Was this page helpful?