关于对truncate的理解



看到了这一题,关于truncate语法的

Evaluate the SQL statement:
TRUNCATE TABLE DEPT;
Which three are 
true about the SQL statement?
 (Choose three.)
A. It releases the storage space used by the table.
B. It does not release the storage space used by the table.
C. You can roll back the deletion of rows after the statement executes.
D. You can NOT roll back the deletion of rows after the statement executes.
E. An attempt to use DESCRIBE on the DEPT table after the TRUNCATE statement
executes will display an error.
F. You must be the owner of the table or have DELETE ANY TABLE system privileges to
truncate the DEPT table
答案是选择 B D F
然后在CU上找到了一篇比较精粹的比较文章,顺便转过来:
truncate,delete,drop的异同点
注意:这里说的delete是指不带where子句的delete语句 
相同点 
truncate和不带where子句的delete, 以及drop都会删除表内的数据 

不同点: 
1
. truncate和 delete只删除数据不删除表的结构(定义) 
    drop语句将删除表的结构被依赖的约束(constrain),触发器(trigger),索引(index); 依赖于该表的存储过程
/
函数将保留,但是变为invalid状态. 
2
.delete语句是dml,这个操作会放到rollback segement中,事务提交之后才生效;如果有相应的trigger,执行的时候将被触发. 
   truncate,drop是ddl, 操作立即生效,原数据不放到rollback segment中,不能回滚. 操作不触发trigger. 
3
.delete语句不影响表所占用的extent, 高水线(high watermark)保持原位置不动 
  显然drop语句将表所占用的空间全部释放 
  truncate 语句缺省情况下见空间释放到 minextents个 extent,除非使用reuse storage;   truncate会将高水线复位(回到最开始). 
4.速度,一般来说: drop>; truncate >
; delete 
5
.安全性:小心使用drop 和truncate,尤其没有备份的时候.否则哭都来不及 
使用上,想删除部分数据行用delete,注意带上where子句. 回滚段要足够大. 
想删除表,当然用drop 
想保留表而将所有数据删除. 如果和事务无关,用truncate即可. 如果和事务有关,或者想触发trigger,还是用delete. 
如果是整理表内部的碎片,可以用truncate跟上reuse stroage,再重新导入
/
插入数据

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值