Small. Fast. Reliable.
Choose any three.

SQLite中的SQL
SQL As Understood By SQLite

[Top]

DROP TABLE

drop-table-stmt:

syntax diagram drop-table-stmt

DROP TABLE语句移除一个由CREATE TABLE语句创建的表。需要指定表名。被卸下的表会完全从数据库和磁盘上删除,无法恢复。该表相关的索引和触发器也都会被删除。
The DROP TABLE statement removes a table added with the CREATE TABLE statement. The name specified is the table name. The dropped table is completely removed from the database schema and the disk file. The table can not be recovered. All indices and triggers associated with the table are also deleted.

选项IF EXISTS 子句防止当表不存在时引发错误。
The optional IF EXISTS clause suppresses the error that would normally result if the table does not exist.

如果设置了外键约束,DROP TABLE命令在从数据库上移除表之前,会隐式执行DELETE FROM <tbl>命令。在隐式执行DELETE FROM <tbl>之前会删除所有附加的触发器,所以不会触发任何触发器。相比之下,隐式DELETE FROM <tbl>会触发所有配置的外键动作。如果隐式DELETE FROM <tbl> 作为DROP TABLE命令的一部分执行违反了任何直接的外键冲突,将会返回一个错误并且表不会被删除。如果隐式DELETE FROM <tbl> 违反任何延迟的外键约束,并且在事务提交时违规依然存在,那么在提交事务的时候会返回一个错误。
If foreign key constraints are enabled, a DROP TABLE command performs an implicit DELETE FROM <tbl> command before removing the table from the database schema. Any triggers attached to the table are dropped from the database schema before the implicit DELETE FROM <tbl> is executed, so this cannot cause any triggers to fire. By contrast, an implicit DELETE FROM <tbl> does cause any configured foreign key actions to take place. If the implicit DELETE FROM <tbl> executed as part of a DROP TABLE command violates any immediate foreign key constraints, an error is returned and the table is not dropped. If the implicit DELETE FROM <tbl> causes any deferred foreign key constraints to be violated, and the violations still exist when the transaction is committed, an error is returned at the time of commit.