truncate命令

2019-10-15  本文已影响0人  做个北漂吧

1. truncate用法

TRUNCATE [TABLE] tbl_name

truncate 用来清空一个数据库表的所有数据。

2.官方解释

Logically, TRUNCATE TABLE is similar to a DELETE statement that deletes all rows, or a sequence of DROP TABLE and CREATE TABLE statements. To achieve high performance, it bypasses the DML method of deleting data. Thus, it cannot be rolled back, it does not cause ON DELETE triggers to fire, and it cannot be performed for InnoDB tables with parent-child foreign key relationships.

上面的意思就是说:从逻辑上讲,TRUNCATE TABLE类似于删除所有行的DELETE语句,或类似于DROP TABLE并CREATE TABLE语句的序列。为了获得高性能,它绕过了删除数据的DML方法。因此,它不能回滚,也不会触发ON DELETE触发器,并且不能在具有父子外键关系的InnoDB表上执行。

DML:数据操纵语言DML(Data Manipulation Language),用户通过它可以实现对数据库的基本操作。

上一篇下一篇

猜你喜欢

热点阅读