ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Sivakumar S , IT Operation Engineer , Ford Motor India Private Ltd
تاريخ النشر: 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
من قبل 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.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟