文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

15.1.32 删除表语句15.1.32 DROP TABLE Statement

DROP [TEMPORARY] TABLE [IF EXISTS]
    tbl_name [, tbl_name] ...
    [RESTRICT | CASCADE]

DROP TABLE 会移除一个或多个表。你必须为每个表设置 DROP 权限。DROP TABLE removes one or more tables. You must have the DROP privilege for each table.

使用此语句时要小心!对于每个表,它会移除表定义和所有表数据。如果表被分区,语句会移除表定义、所有分区、这些分区中存储的所有数据,以及与丢弃表相关的所有分区定义。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隐式提交,除非与 TEMPORARY。参见 第 15.3.3 节,“导致隐式提交的语句”。DROP TABLE causes an implicit commit, except when used with the TEMPORARY keyword. See Section 15.3.3, “Statements That Cause an Implicit Commit”.

Important

当一个表格被丢弃时,专门为该表授予的权限是不会自动放弃。这些权限必须手动丢弃。参见 第 15.7.1.6 节,“GRANT Statement”。When a table is dropped, privileges granted specifically for the table are not automatically dropped. They must be dropped manually. See Section 15.7.1.6, “GRANT Statement”.

如果参数列表中没有任何表,DROP TABLE 行为取决于是否给出 IF EXISTS子句:If any tables named in the argument list do not exist, DROP TABLE behavior depends on whether the IF EXISTS clause is given:

  • 如果没有 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,不存在的表不会发生错误。该语句会丢弃所有存在的命名表,并为每个不存在的表生成一个 NOTE 诊断。这些笔记可以显示为 SHOW WARNINGS“。参见 第 15.7.7.42 节,”SHOW WARNINGS Statement“。With IF EXISTS, no error occurs for nonexisting tables. The statement drops all named tables that do exist, and generates a NOTE diagnostic for each nonexistent table. These notes can be displayed with SHOW WARNINGS. See Section 15.7.7.42, “SHOW WARNINGS Statement”.

IF EXISTS在数据字典有条目但存储引擎管理的表没有表的情况下,也可用于丢弃表。(例如,在数据字典条目移除后发生异常服务器退出。)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. (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.)

TEMPORARY 关键字具有以下效果:The TEMPORARY keyword has the following effects:

  • 该语句仅丢弃 TEMPORARY 表。The statement drops only TEMPORARY tables.

  • 该语句不会引发隐式提交。The statement does not cause an implicit commit.

  • 没有检查访问权限。TEMPORARY 表仅在创建它的会话中可见,因此不需要进行检查。No access rights are checked. A TEMPORARY table is visible only with the session that created it, so no check is necessary.

包括 TEMPORARY 关键字是防止意外删除非 TEMPORARY 表的好方法。Including the TEMPORARY keyword is a good way to prevent accidentally dropping non-TEMPORARY tables.

RESTRICT 和 CASCADE 关键字没有作用。它们的存在是为了方便从其他数据库系统迁移。The RESTRICT and CASCADE keywords do nothing. They are permitted to make porting easier from other database systems.

DROP TABLE 并不支持所有 innodb_force_recovery 设置。详见 第 17.20.3 节,“强制 InnoDB 恢复”。DROP TABLE is not supported with all innodb_force_recovery settings. See Section 17.20.3, “Forcing InnoDB Recovery”.