8

How to rollback delete command without using transaction ? if we can't , then what's the difference between Truncate & delete ?

3
  • 2
    Which Platform are we talking about here? Commented Mar 18, 2013 at 8:54
  • not enough informations given.
    – bot
    Commented Mar 18, 2013 at 9:03
  • am writing the code in SQL Server 2012 .
    – Nim J
    Commented Mar 18, 2013 at 9:08

3 Answers 3

4

You cannot rollback in this case, but when you are using the Full Recovery Model, then you can turn your database back to the moment before you issued the delete command.

2

You cannot ROLLBACK an operation without a transaction. You could probably use implicit transactions, but you still need to call COMMIT or ROLLBACK explicitly. However, for better control, it's better to wrap the statement(s) in a BEGIN TRANSACTION...COMMIT / ROLLBACK block anyway. This way you'll avoid any confusion and the need to use the IMPLICIT_TRANSACTION setting.

2

You can roll back DELETE or TRUNCATE (and most other operations) if and only if they are part of a transaction that's not yet committed. Alternatively you could restore the deleted/truncated data from a backup.

There are several differences between TRUNCATE and DELETE. Most notably TRUNCATE can only empty a table whereas DELETE deletes just the rows you specify. TRUNCATE deallocates and logs data at the page level instead of row level, which typically makes TRUNCATE a more efficient method than DELETE for deleting the entire content of a table.

1
  • 2
    If he is using a full recovery model, then he could turn back the database to the moment before the delete command was issued.
    – SQL Police
    Commented Jul 3, 2015 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.