Use the TRUNCATE statement to remove all rows from a table or cluster and reset the STORAGE parameters to the values when the table or cluster was created. Deleting rows with the TRUNCATE statement can be more efficient than dropping and re-creating a table. Dropping and re-creating a table invalidates the table's dependent objects, requires you to regrant object privileges on the table, and requires you to re-create the table's indexes, integrity constraint, and triggers and respecify its storage parameters. Truncating has none of these effects.

解决方案 »

  1.   

    TRUNCATE TABLE tab_a的意思是删除表tab_a中的所有记录,因为不能rollback,所以效率要高于delete. 下面是Oracle的帮助。
    To remove all rows from a table or cluster and reset the STORAGE parameters to
    the values when the table or cluster was created.REUSE STORAGE
    retains the space from the deleted rows allocated to the table or cluster. Storage values are not reset to the values when the table or cluster was created. This space can subsequently be used only by new data in the table or cluster resulting from inserts or updates.
    The DROP STORAGE clause and REUSE STORAGE clause also apply to the space freed by
    the data deleted from associated indexes.
      

  2.   

    REUSE STORAGE 
     Specify REUSE STORAGE to retain the space from the deleted rows allocated to the table or cluster. Storage values are not reset to the values when the table or cluster was created. This space can subsequently be used only by new data in the table or cluster resulting from inserts or updates. 
      

  3.   

    truncate table 就是清空表,与drop table和delete from tablename 相似,
    但drop table 是将表结构和记录一同清除,且不可恢复。
    truncate table 是将记录清除,且不可恢复,但保留表结构。
    delete from 清空记录,但可以在commit之前进行rollback.
      

  4.   

    REUSE  STORAGE    
    有什么用呢,是不是保留原有的空间,为以后再insert数据用的呢?
    这样没有什么意义啊?
      

  5.   

    TRUNCATE和DELETE有以下几点区别  1、TRUNCATE在各种表上无论是大的还是小的都非常快。如果有ROLLBACK命令DELETE将被撤销,而TRUNCATE则不会被撤销。  2、TRUNCATE是一个DDL语言,向其他所有的DDL语言一样,他将被隐式提交,不能对TRUNCATE使用ROLLBACK命令。  3、TRUNCATE将重新设置高水平线和所有的索引。在对整个表和索引进行完全浏览时,经过TRUNCATE操作后的表比DELETE操作后的表要快得多。  4、TRUNCATE不能触发任何DELETE触发器。  5、不能授予任何人清空他人的表的权限。  6、当表被清空后表和表的索引讲重新设置成初始大小,而delete则不能。  7、不能清空父表。
      

  6.   

    这对Oracle将来插入新记录时是有用的。
      

  7.   

    TRUNCATE TABLE tab_a REUSE STORAGE
    快速删除表,不写日志,保留存储介质中的数据。