DROP [TEMPORARY] TABLE [IF EXISTS]tbl_name
[,tbl_name
] ... [RESTRICT | CASCADE]
DROP TABLE
removes one or more tables. DROP TABLE
删除一个或多个表。You must have the 您必须具有每个表的DROP
privilege for each table.DROP
权限。
Be careful with this statement! For each table, it removes the table definition and all table data. 小心这句语句!对于每个表,它将删除表定义和所有表数据。If the table is partitioned, the statement removes the table definition, all its partitions, all data stored in those partitions, and all partition definitions associated with the dropped table.如果表已分区,则该语句将删除表定义、其所有分区、存储在这些分区中的所有数据以及与删除的表关联的所有分区定义。
Dropping a table also drops any triggers for the table.删除表也会删除该表的所有触发器。
DROP TABLE
causes an implicit commit, except when used with the TEMPORARY
keyword. DROP TABLE
导致隐式提交,除非与临时关键字一起使用。See Section 13.3.3, “Statements That Cause an Implicit Commit”.请参阅第13.3.3节,“导致隐式提交的语句”。
When a table is dropped, privileges granted specifically for the table are not automatically dropped. 删除表时,不会自动删除专门为该表授予的特权。They must be dropped manually. 必须手动删除它们。See Section 13.7.1.6, “GRANT Statement”.请参阅第13.7.1.6节,“GRANT语句”。
If any tables named in the argument list do not exist, 如果参数列表中命名的任何表不存在,则DROP TABLE
behavior depends on whether the IF EXISTS
clause is given:DROP TABLE
行为取决于是否给定IF EXISTS
子句:
Without 如果没有IF EXISTS
, the statement fails with an error indicating which nonexisting tables it was unable to drop, and no changes are made.IF EXISTS
,该语句将失败,并出现一个错误,指示它无法删除哪些不存在的表,并且不会进行任何更改。
With 使用IF EXISTS
, no error occurs for nonexisting tables. IF EXISTS
,则不存在的表不会发生错误。The statement drops all named tables that do exist, and generates a 该语句删除所有确实存在的命名表,并为每个不存在的表生成NOTE
diagnostic for each nonexistent table. NOTE
诊断。These notes can be displayed with 这些注释可以利用SHOW WARNINGS
. SHOW WARNINGS
显示。See Section 13.7.7.42, “SHOW WARNINGS Statement”.请参阅第13.7.7.42节,“SHOW WARNINGS语句”。
IF EXISTS
can also be useful for dropping tables in unusual circumstances under which there is an entry in the data dictionary but no table managed by the storage engine. IF EXISTS
还可用于在数据字典中有条目但存储引擎没有管理表的异常情况下删除表。(For example, if an abnormal server exit occurs after removal of the table from the storage engine but before removal of the data dictionary entry.)(例如,如果在从存储引擎中删除表之后但在删除数据字典条目之前发生异常服务器退出。)
The TEMPORARY
keyword has the following effects:TEMPORARY
关键字具有以下效果:
The statement drops only 该语句只删除TEMPORARY
tables.TEMPORARY
表。
The statement does not cause an implicit commit.该语句不会导致隐式提交。
No access rights are checked. 未检查任何访问权限。A TEMPORARY
table is visible only with the session that created it, so no check is necessary.TEMPORARY
表仅在创建它的会话中可见,因此无需进行检查。
Including the 包含TEMPORARY
keyword is a good way to prevent accidentally dropping non-TEMPORARY
tables.TEMPORARY
关键字是防止意外删除非TEMPORARY
表的好方法。
The RESTRICT
and CASCADE
keywords do nothing. RESTRICT
和CASCADE
关键字不起任何作用。They are permitted to make porting easier from other database systems.它们允许更容易地从其他数据库系统进行移植。
并非所有DROP TABLE
is not supported with all innodb_force_recovery
settings. innodb_force_recovery
设置都支持DROP TABLE
。See Section 15.21.2, “Forcing InnoDB Recovery”.请参阅第15.21.2节,“强制InnoDB
恢复”。