Archive for the ‘SQL’ Category

Delete vs Truncate in SQL

Monday, March 12th, 2007

If you want to quickly remove all rows of data in a table, use [TRUNCATE] command. Sample SQL statement using [TRUNCATE] command :

TRUNCATE TABLE [tablename]

All indexes, triggers, and structures still remain intact. It is faster than [DELETE] command because when using [DELETE] command, the data is removed and logs as transaction one row at a time. On the other hand, [TRUNCATE] will deallocate the entire data page in the table and reduces the number of logs activities; thus performs better compare to [DELETE] command.

Sample using [DELETE] command:

  1. DELETE FROM [table name]
  2. DELETE FROM [table name] WHERE [clauses]

If you like this post, you may want to subscribe to my RSS feed.