SQL Myth–Cannot truncate table in a transaction

When asked about the difference between a truncate and delete the common answer is that delete is a logged operation but truncate is not.  Well sort of.  Referring to BOL truncate is a minimally logged operation.  SQL Server doesn’t keep track of the rows during a truncate but it does keep track of the pages.  As a result it can be used inside a transaction.    In this simple example there is a table with seven rows that gets truncated inside the transaction.  As you can see after the transaction is rolled back the seven rows are still there.

image

Advertisements
This entry was posted in Database Administration and tagged , , , . Bookmark the permalink.

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