Frage

I have been using "delete from table_xyz" to delete everything in the table. Would it be better to instead use truncate? What difference does it make?

War es hilfreich?

Lösung

My short answer is:

Use truncate if you do not see any errors (because truncate cannot be used in many scenarios, such as the table is referenced or the table is in replication, but you will get error in such cases)

The advantages of truncate (over delete esp. in your repeated deletion case) are:

  1. fast as it does not involve big overhead of transaction logging.
  2. much smaller footprint on database log.

Hope this helps !

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit dba.stackexchange
scroll top