Search This Blog

Tuesday, March 27, 2012

DELETE and TRUNCATE can be rolled back


As we all know, DELETE can be rolled be back even if it is committed, using the log file and some third party to tools.

Truncate can also be rolled back, if it is within a TRANSACTION and if the session is not closed.

Try the below code, first create a table, then insert some data into it. Then run these set of lines. You should get some data before truncate is run, after truncate there shouldn't be no data and after rollback, if the original data is returned then TRUNCATE CAN be rolled back.

NOTE: I am running this code in SQL SERVER 2008


BEGIN TRANSACTION

SELECT * FROM table1

TRUNCATE TABLE table1

SELECT * FROM table1

ROLLBACK

SELECT * FROM table1

No comments:

Post a Comment