当前位置:网站首页>MySQL数据库:drop、truncate、delete的区别
MySQL数据库:drop、truncate、delete的区别
2022-06-29 13:05:00 【全栈程序员站长】
1、删除速度:drop>truncate>delete;
2、删除方式:
- (1)执行delete操作时,每次从表中删除一行,并且同时将该行的的删除操作记录在日志文件中。delete可根据where条件删除表中指定的数据,如果不指定where子句,则跟truncate一样,可以删除表中所有记录。
- (2)truncate通过释放存储表数据所用的页来删除数据,一次性删除表中所有记录,不会将删除的数据记录在日志文件中,只在日志文件中记录页的释放,使用的系统和事务日志资源少,所以执行速度比delete快。对于外键约束引用的表,不能使用 truncate table,而应使用不带 where 子句的 delete 语句。
- (3)drop则删除整个表的结构和数据,但是被依赖的约束、触发器、索引、依赖于该表的存储过程、函数将被保留,但其状态会变为invalid
3、删除后,表和索引所占空间:
- (1)delete操作不会减少表或索引所占用的空间;
- (2)当表被truncate后,这个表和索引所占用的空间会恢复到初始大小,但表结构及其列、约束、索引的定义等保持不变。
- (3)drop语句将表所占用的空间全释放掉。
4、提交方式:delete是DML,需要手动提交操作才能生效,可以回滚,可以触发触发器;truncate和drop是DDL,会隐式提交,不能回滚,不会触发触发器。
5、使用场景:
- (1)如果想删除表,当然用drop;
- (2)如果想保留表而将所有数据删除,而且和事务无关,用truncate即可;
- (3)如果和事务有关,或者想触发trigger,还是用delete;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100076.html原文链接:https://javaforall.cn
边栏推荐
- 微信小程序:万圣节头像框生成工具
- 逆向调试入门-PE文件节表与区块03/07
- 微信小程序:(更新)云开发微群人脉
- Xiaobai learns MySQL - incremental statistical SQL requirements - windowing function scheme
- Don't build the wheel again. It is recommended to use Google guava open source tool class library. It is really powerful!
- urllib urllib2
- 灵感收集·创意写作软件评测:Flomo、Obsidian Memo、Napkin、FlowUs
- 【VEUX开发者工具的使用-getters使用】
- Problems in replacing RESNET convolution of mmdet with ghost convolution group
- 直觉与实现:Batch Normalization
猜你喜欢

Weserver publishing map service

win11怎么看cpu几核几线程? win11查看cpu是几核几线程的教程

How to make dapper support dateonly type

Uncover the practice of Baidu intelligent test in the field of automatic test execution

记一次 .NET 某物管后台服务 卡死分析

Intuition and Implementation: batch normalization

sqlite3入门

windows平台下的mysql启动等基本操作

Discard Tkinter! Simple configuration to quickly generate cool GUI!

System. Currenttimemillis() and system Nanotime() which is faster? Most people get the wrong answer!
随机推荐
[high concurrency] 28000 words' summary of callable and future interview knowledge points. After reading it, I went directly to ByteDance. Forgive me for being a little drifting (middle)
微信小程序:(更新)云开发微群人脉
Detailed explanation of PDB symbol library files
urllib urllib2
WinDbg debugging tool introduction
Xiaobai learns MySQL - incremental statistical SQL requirements - windowing function scheme
关于MongoDB报错:connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
goby全端口扫描
MySQL数据库:使用show profile命令分析性能
微信小程序:装B神器P图修改微信流量主小程序源码下载趣味恶搞图制作免服务器域名
##Mondo Rescue制作镜像文件(有利于镜像损坏恢复)
Open source machine learning platform
现场快递柜状态采集与控制系统
Weserver Publishing Map Service
PG Basics - logical structure management (1)
微信小程序:修复采集接口版云开发表情包
[graduation season · advanced technology Er] 10.76 million graduates, the most difficult employment season in history? I can't roll it up again. I lie down again and again. Where is the road?
Stable currency risk profile: are usdt and usdc safe?
Leetcode question brushing: String 07 (repeated substring)
Wechat applet: Halloween avatar box generation tool