MySQL DELETE语句和TRUNCATE TABLE
PHP中文网
PHP中文网 2017-04-17 11:02:19
[MySQL讨论组]

两者到底有什么区别, 据说 TRUNCATE 操作, binlog 也恢复不了。

PHP中文网
PHP中文网

认证0级讲师

全部回复(2)
ringa_lee

个人理解:truncate是对表结构的一种重置功能,通过truncate之后,表会自动恢复到create时的状态,它不仅仅是数据删除的问题,而是整个表结构的恢复,例如你的row_id如果是auto increment的,delete是不会影响它的,如果是truncate,那么它就会恢复到了初始值了。

高洛峰

truncate不记录日志,不能从日志中恢复数据

The TRUNCATE TABLE statement is a fast, nonlogged method of deleting all rows in a table. It is almost always faster than a DELETE statement with no conditions because DELETE logs each row deletion, and TRUNCATE TABLE logs only the deallocation of whole data pages. TRUNCATE TABLE immediately frees all the space occupied by that table's data and indexes. The distribution pages for all indexes are also freed.

As with DELETE, the definition of a table emptied using TRUNCATE TABLE remains in the database, along with its indexes and other associated objects. The DROP TABLE statement must be used to drop the definition of the table.

REF: http://bbs.csdn.net/topics/80111360

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号