T-SQL - Rollback or Undo Changes

I am relatively new to T-SQL... coming from years of using MS Access.
'Un-doing' a change in Access was relatively easy, even backing it up and restoring, if needed.

What is the easiest way to un-do something in MS SQL, without a full restore?


Frank GrimesAsked:
Who is Participating?
lcohanConnect With a Mentor Database AnalystCommented:
Easiest is not the best..you need to wrap each and any of your transactions in a explicit BEGIN/COMMIT but again..just do NOT do that as you'll be looking for trouble in MSSQL server.

Best approach in my opinion would be to run a BEGIN/TRY/CATCH sequence and rollback on any error. More learning and coding but infinitely better and faster and less (actually nothing at all) trouble.

Other than that you could play with different type of connections/transactions isolation levels but again, that's maybe troublesome if you don't know exactly what you are doing.
Eugene ZConnect With a Mentor Commented:
it is a very similar to VBA.
..additionally to Rollback (above posts)
you can try
When SET XACT_ABORT is ON, if a Transact-SQL statement raises a run-time error, the entire transaction is terminated and rolled back.
Vitor MontalvãoConnect With a Mentor MSSQL Senior EngineerCommented:
UNDO doesn't exist in SQL Server.
You can always work with transactions so at the end you can decide to COMMIT (accept) or ROLLBACK (discard) the changes.

Backup and Restore exists in all DBMS so SQL Server isn't an exception but we should be aware of the different backup types and the way to restore them.
Frank GrimesAuthor Commented:
Thanks guys!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.