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

DROP TABLE - 图1

OptTemporary

DROP TABLE - 图2

TableOrTables

DROP TABLE - 图3

TableNameList

DROP TABLE - 图4

  1. DropTableStmt ::=
  2. 'DROP' OptTemporary TableOrTables IfExists TableNameList RestrictOrCascadeOpt
  3. OptTemporary ::=
  4. ( 'TEMPORARY' | ('GLOBAL' 'TEMPORARY') )?
  5. TableOrTables ::=
  6. 'TABLE'
  7. | 'TABLES'
  8. TableNameList ::=
  9. TableName ( ',' 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

  1. mysql> CREATE TABLE t1 (a INT);
  2. Query OK, 0 rows affected (0.11 sec)
  3. mysql> DROP TABLE t1;
  4. Query OK, 0 rows affected (0.22 sec)
  5. mysql> DROP TABLE table_not_exists;
  6. ERROR 1051 (42S02): Unknown table 'test.table_not_exists'
  7. mysql> DROP TABLE IF EXISTS table_not_exists;
  8. Query OK, 0 rows affected, 1 warning (0.01 sec)
  9. mysql> SHOW WARNINGS;
  10. +-------+------+---------------------------------------+
  11. | Level | Code | Message |
  12. +-------+------+---------------------------------------+
  13. | Note | 1051 | Unknown table 'test.table_not_exists' |
  14. +-------+------+---------------------------------------+
  15. 1 row in set (0.01 sec)
  16. mysql> CREATE VIEW v1 AS SELECT 1;
  17. Query OK, 0 rows affected (0.10 sec)
  18. mysql> DROP TABLE v1;
  19. Query OK, 0 rows affected (0.23 sec)

MySQL compatibility

Currently, RESTRICT and CASCADE are only supported syntactically.

See also