oracle中的truncate与delelte
转自:http://hi.baidu.com/grace_king/blog/item/cb82930ad6249134b0351d6e.html
delete: Use the DELETE statement to remove rows from a table, a partitioned table, a view's base table, or a view's partitioned base table.
truncate:Use the TRUNCATE statement to remove all rows from a table or cluster. By default, Oracle also deallocates all space used by the removed rows except that specified by the MINEXTENTS storage parameter and sets the NEXT storage parameter to the size of the last extent removed from the segment by the truncation process.
truncate的功能可以拆分为:dropping + re-creating a table,但truncate的效率要高。因为truncate无须考虑表索引、约束、触发器等的重建。
另外truncate执行后,无法回滚(roll back)
HWM(high water mark,最高水位线):The high water mark is divides a segment into used blocks and free blocks Blocks below the high water mark (used blocks) have at least once contained data. This data might have been deleted. Since Oracle knows that blocks beyond the high water mark don't have data, it only reads blocks up to the high water mark in a full table scan(FTS).在oracle10g中增加了调整HWM的命令:alter table xxx shrink space。
以下网上达人总结的truncate与delete区别:
1、在功能上,truncate是清空一个表的内容,它相当于delete from table_name。
2、delete是dml操作,truncate是ddl操作;因此,用delete删除整个表的数据时,会产生大量的roolback,占用很多的rollback segments, 而truncate不会。
3、在内存中,用delete删除数据,表空间中其被删除数据的表占用的空间还在,便于以后的使用,另外它是“假相”的删除,相当于windows中用delete删除数据是把数据放到回收站中,还可以恢复,当然如果这个时候重新启动系统(OS或者RDBMS),它也就不能恢复了!
而用truncate清除数据,内存中表空间中其被删除数据的表占用的空间会被立即释放,相当于windows中用shift+delete删除数据,不能够恢复!
4、truncate 调整high water mark 而delete不;truncate之后,TABLE的HWM退回到 INITIAL和NEXT的位置(默认)delete 则不可以。
5、truncate 只能对TABLE,delete 可以是table,view,synonym。
6、TRU
相关文档:
Create directory让我们可以在Oracle数据库中灵活的对文件进行读写操作,极大的提高了Oracle的易用性和可扩展性。
其语法为:
CREATE [OR REPLACE] DIRECTORY directory AS 'pathname';
本案例具体创建如下:
create or replace directory exp_dir as '/tmp';
目录创建以后,就可以把读写权限授予特定用户 ......
一、 内存结构
共享池:分为库高速缓存和字典高速缓冲区
库高速缓存,用于存储经过语法分析并且正确的SQL语句,并随时准备执行。
字典高速缓冲区,存储登陆到ORACLE的用户名,及这些用户有哪些数据库对象以及这些数据库对象的位置。
数据缓 ......
ORACLE游标
游标:容器,存放当前SQL语句影响的记录
所有DML语句都会用到游标
逐行处理影响的行数
游标
静态游标:游标与SQL语句在运行前关联
&nb ......
触发器
q 触发器是当特定事件出现时自动执行的存储过程
q 特定事件可以是执行更新的DML语句和DDL语句
q 触发器不能被显式调用
q 触发器的功能:
q ......
不错的资料,转过来,方便日后查看使用!!!
--监控索引是否使用
alter index &index_name monitoring usage;
alter index &index_name nomonitoring usage;
select * from v$object_usage where index_name =
&index_name;
--求数据文件的I/O分布
select
df.name,phyrds,phywrts,phyblkrd,phyblkwrt,sin ......