Home > Database > Mysql Tutorial > body text

DELETE与TRUNCATE有什么不同

WBOY
Release: 2016-06-07 16:19:19
Original
1202 people have browsed it

DELETE与TRUNCATE有什么不同 删除表中的数据的方法有delete,truncate, 它们都是删除表中的数据,而不能删除表结构,delete 可以删除整个表的数据也可以删除表中某一条或N条满足条件的数据,而truncate只能删除整个表的数据,一般我们把delete 操作叫作删除表,而t

   DELETE与TRUNCATE有什么不同

  删除表中的数据的方法有delete,truncate,

  它们都是删除表中的数据,而不能删除表结构,delete 可以删除整个表的数据也可以删除表中某一条或N条满足条件的数据,而truncate只能删除整个表的数据,一般我们把delete 操作叫作删除表,而truncate操作叫作截断表.

  truncate 操作与 delete 操作对比

  操作

  回滚

  高水线

  空间

  效率

  Truncate

  不能

  下降

  回收

  快

  delete

  可以

  不变

  不回收

  慢

  TRUNCATE和DELETE有以下几点区别

  1、TRUNCATE在各种表上无论是大的还是小的都非常快。如果有ROLLBACK命令DELETE将被撤销,而TRUNCATE则不会被撤销。

  2、TRUNCATE是一个DDL语言,向其他所有的DDL语言一样,他将被隐式提交,不能对TRUNCATE使用ROLLBACK命令。

  3、TRUNCATE将重新设置高水平线和所有的索引。在对整个表和索引进行完全浏览时,经过TRUNCATE操作后的表比DELETE操作后的表要快得多。

  4、TRUNCATE不能触发任何DELETE触发器。

  5、不能授予任何人清空他人的表的权限。

  6、当表被清空后表和表的索引将重新设置成初始大小,而delete则不能。

  7、不能清空父表。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!