Saturday, February 13, 2010

Oracle: Difference between Truncate & Delete

  • DELETE is a DML command and deleted data
    gets copied to Rollback Tablespace which can be rolled back.
  • DELETE is a logged operation on a per row basis. This means that the deletion of each row gets logged into Redo log file and physically deleted.
  • You can DELETE any row that will not violate a constraint, while leaving the foreign key or any other constraint in place.
  • DELETE will not reset the identity column.
  • DELETE: You can use WHERE clause with DELETE Statement.
  • DELETE: Fires Triggers
  • TRUNCATE is a DDL command and cannot be rolled back (delete + commit) . All of the memory space is released back to the server.
  • TRUNCATE is also a logged operation, but in a different way. TRUNCATE logs the deallocation of the data pages in which the data exists. The deallocation of data pages means that your data rows still actually exist in the data pages, but the extents have been marked as empty for reuse. This is what makes TRUNCATE a faster operation to perform over DELETE.
  • You cannot TRUNCATE a table that has any foreign key constraints. You will have to remove the constraints, TRUNCATE the table, and reapply the constraints.
  • TRUNCATE will reset any identity columns to the default seed value.
  • TRUNCATE You can't use WHERE clause.
  • TRUNCATE does not write any date in redo log files.
  • TRUNCATE does not fire any triggers. DELETE Fires Triggers.

No comments:

Post a Comment