Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the difference between truncate and delete table in database ?

user-image
Question added by Sivakumar S , IT Operation Engineer , Ford Motor India Private Ltd
Date Posted: 2013/10/14
Deleted user
by Deleted user

Delete

The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. Note that this operation will cause all DELETE triggers on the table to fire.

Truncate

TRUNCATE removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUCATE is faster and doesn't use as much undo space as a DELETE.

Mahaboob Basha Sahik
by Mahaboob Basha Sahik , Sr Dynamic CRM Consultant , Dimension Data

Truncate:

  • Works by deallocating all the data pages in the table.
  • Will delete all data - you cannot restrict it with a WHERE clause.
  • Deletions are not logged.
  • Triggers are not fired.
  • Cannot be used if any foreign keys reference the table.
  • Resets auto id counters.
  • Faster.

Delete:

  • Works by deleting row by row.
  • Can be restricted with a WHERE clause.
  • Deletions are logged in the transaction log (if you have logging on obviously) so the delete can be recovered if necessary (depending on your logging settings).
  • Triggers are fired.
  • Can be used on tables with foreign keys (dependant on your key cascade settings).
  • Slower.

More Questions Like This