简体   繁体   English

MySQL:“DROP TABLE”是完全删除表还是只删除结构?

[英]MySQL: Does `DROP TABLE` completely remove the table or just the structure?

I am under the impression that the MySQL command DROP TABLE User will just remove the data, columns, and relevant constraints. 我的印象是MySQL命令DROP TABLE User将只删除数据,列和相关约束。 However, the table shell still exists. 但是,表shell仍然存在。 Is this correct? 它是否正确?

Using DROP TABLE will remove the entire table and all records contained inside it. 使用DROP TABLE将删除整个表及其中包含的所有记录。 If you want to retain the table structure but remove all data, then consider using TRUNCATE TABLE . 如果要保留表结构但删除所有数据,请考虑使用TRUNCATE TABLE Truncating a table is implemented by dropping the entire table and then recreating it. 截断表是通过删除整个表然后重新创建它来实现的。 This is faster than doing DELETE FROM yourTable , which removes records one-by-one. 这比执行DELETE FROM yourTable更快,后者DELETE FROM yourTable删除记录。

After Drop Table , the table will not exist anymore, so no data and no table definition(which you called 'table shell'); Drop Table ,该表将不再存在,因此没有数据也没有表定义(你称之为'table shell'); TRUNCATE TABLE keep your table definition and delete all the data ,and reset table auto-increment as well, but be careful about TRUNCATE if the table size is huge, it will expand your tablespace and not easy to shrink. TRUNCATE TABLE保留你的表定义并删除所有数据,并重置表自动增量,但如果表大小很大,请注意TRUNCATE ,它会扩展你的表空间而不容易缩小。

As mysql manual on drop table says: 正如drop table上的mysql手册所说:

Be careful with this statement! 小心这个说法! It removes the table definition and all table data. 它删除表定义和所有表数据。

So, no shell (whatever that should mean) remains after dropping a table. 因此,在删除表之后,没有shell(无论应该是什么意思)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM