Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Sivakumar S , IT Operation Engineer , Ford Motor India Private Ltd
Date de publication: 2013/10/14

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
par Mahaboob Basha Sahik , Module Lead , Tech Mahindra

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

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?