Mysql中delete、truncate、drop的异同和使用场景
| SQL类型 | 常见用法 | 主要用法 | 是否删除数据? | 是否释放空间? | 是否删除相关索引? | 是否删除表格? | |
| delete | DML |
1)delete from table_name where ... 2)delete from table_name |
-- 删除表中部分符合条件的数据 -- delete from table_name where ...
|
Y |
N | N | N |
| truncate | DDL |
truncate table table_name |
-- 清空表中的数据,但保留表 -- truncate table table_name |
Y | Y | Y | N |
| drop | DDL |
drop table table_name |
-- 清理与该表相关的所有内容,包括表自己 -- drop table table_name |
Y | Y | Y | Y |
浙公网安备 33010602011771号