Saturday, October 3, 2015

SQL - Delete vs Drop vs Truncate

  1. DELETE operation remove some or all rows and need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. will cause all DELETE triggers on the table to fire.
  2. TRUNCATE removes all rows  from a table and no DML triggers will be fired.
  3. DROP removes a table from the database, indexes and privileges, No DML triggers will be fired.
  • DROP and TRUNCATE are DDL commands, DELETE is a DML command.
    Therefore DELETE operations can be rolled back (undone), while DROP and TRUNCATE operations cannot be rolled back.
  • TRUCATE is faster and doesn't use as much undo space as a DELETE.
  • Specify CASCADE CONSTRAINTS to drop all referential integrity constraints(at the detail table) that refer to primary and unique keys in the dropped table. If you omit this clause, and such referential integrity constraints exist, then the database returns an error and does not drop the table.
           Example
                drop table Dept cascade constraints 

http://www.orafaq.com/faq/difference_between_truncate_delete_and_drop_commands

No comments:

Post a Comment

java - fill distinct objects in ArrayList

If you have a list that contains some objects that it is considered as duplication when two or three fields of these objects are equal. How ...