SQL: Truncate vs Delete

Truncate:

– deallocates the data pages in a table and only this deallocation is stored in transaction log

– aquires only table and page locks for the whole table. since no
row locks are used less memory is required (lock is a pure memory
object)

– resets identity column if there is one

– removes ALL pages. NO empty pages are left behind in a table

– fast(er)

– doesn’t fire delete triggers

Delete:

– removes one row at the time and every deleted row is stored in the transaction log

– aquires table and/or page and row locks for the whole table

– leaves identity column alone

– can leave empty pages in a table since empty page removal requires a table lock which doesn’t necessarily happen

– slow(er)

– fires delete triggers

[ref]

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: