当前位置:网站首页>Explain the difference between Oracle DELETE and TRUNCATE
Explain the difference between Oracle DELETE and TRUNCATE
2022-08-05 16:17:00 【HUAWEI CLOUD】
1. Grammar
delete from table aa truncate table aa code>Second, the difference
Conditions can be written after
delete from, but nottruncate.delete fromrecords are deleted one by one, and each deleted line of records will be entered into the log, andtruncatedeletes the entire page at one time, so onlyRecord page release, in short, delete fromupdate log,truncatebasically not, the transaction log space used is less.delete fromwill leave an empty page after deleting an empty table, andtruncatewill not leave any pages in the table.- When a
DELETEstatement is executed with row locks, the rows in the table are locked for deletion.truncatealways locks tables and pages, not individual rows.- If there is an auto-increment id column generated by
identity, afterdelete fromit still increases from the last number, that is, the seed remains unchanged, andtruncate, the seed will be restored to its original state.truncatedoes not fire the trigger fordeletebecause thetruncateaction does not record individual row deletions.
3. Summary
truncateanddeleteonly delete the data, not the structure (definition) of the table; The dropstatement will drop constraints (constrain), triggers (trigger), indexes (index); Stored procedures/functions that depend on this table will remain, but becomeinvalidstatus.- The
deletestatement isdml, this operation will be placed in rollback segement, it will take effect after the transaction is committed;If there is a correspondingtrigger, it will be triggered when executed;truncate,dropisddl, the operation is immediateEffective, the original data will not be placed in therollback segment, cannot be rolled back, and the operation will not triggertrigger. The deletestatement does not affect theextentoccupied by the table, and the high watermark remains in its original position; obviously thedropstatementFree all the space occupied by the table.Thetruncatestatement by default frees space tominextentsextents,unless reuse storage;truncatewill reset the high watermark (back to the beginning).- Speed, in general:
drop>truncate>delete. - Security: Be careful with
dropandtruncate, especially if there is no backup, otherwise it will be too late to cry. - In use, if you want to delete some data rows, use
delete, and pay attention to thewhereclause.The rollback segment should be large enough; want to drop the table.Of course withdrop; delete all data if you want to keep the table.If it has nothing to do with the transaction, usetruncate.If it is related to a transaction, or if you want to triggertrigger, usedelete; if it is to sort out the fragments inside the table, you can usetruncateto keep up with reuse stroage, and then re-import/insert the data.
边栏推荐
- Image Edge Detection - First Order Differential Operator Roberts, Sobel, Prewitt, Kirsch, Robinson
- Study Notes 227—Word automatic catalog, there is a space after the catalog number, how can I set it to remove it?
- 你总说毕业遥遥无期,转眼就各奔东西
- 华为云鲲鹏ARM服务器使用MCSM9搭建 我的世界(MC) 1.18.2 版服务器教程
- vu2 尚硅谷 组件化编程
- 【案例】一个熊在跑的动画animation
- 学习笔记220—office2016无法登录账号,提示“很抱歉遇到一些临时服务器问题”?
- "Avnet Embedded Weekly" Issue 276: 2022.07.25--2022.07.3
- 一个案例搞懂工厂模式和单例模式
- C语言之链表简单操作(亲测可用)
猜你喜欢
随机推荐
Instant messaging development long connection gateway technology: WebSocket real-time push gateway technology
ASIC和FPGA设计流程
The annual gas transmission volume of the West-East Gas Pipeline exceeds 100 billion cubic meters for the first time, and Tupu helps pipeline monitoring
数据库篇——hash索引
黑马瑞吉外卖之员工账号的禁用和启用以及编辑修改
Redis-浅谈主从同步
即时通讯开发长连接网关技术:WebSocket实时推送网关技术
Further dissection and application of disappearing heritability
Poisson Image Editing
High Numbers_Prove_The Clamping Criterion of the Existence of Limits
Monotonic Bounded Criterion for High Numbers_Prove_Limit Existence
playwright录制脚本
『攻防』记一次EDU攻防演练
实战|记一次某系统的渗透测试
学习笔记238— 如何在word文档中快速输入各类根号【根号下没输入数字,也不会出现虚线框】
编译器工程师眼中的好代码:Loop Interchange
某次红蓝对抗之Solr-RCE实战绕过
Oracle导数据
JVM内存和垃圾回收-09.对象的实例化内存布局与访问定位
学习笔记227—Word自动目录,目录编号后面有空格,怎样设置能去掉?









