Mysql中delete、truncate、drop的异同和使用场景

  SQL类型 常见用法 主要用法 是否删除数据? 是否释放空间? 是否删除相关索引? 是否删除表格?
delete DML
1delete from table_name where ...
2delete 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



posted on 2021-09-14 22:35  呼延灼  阅读(85)  评论(0)    收藏  举报

导航