Solved

T-SQL - Rollback or Undo Changes

Posted on 2016-09-09
4
66 Views
Last Modified: 2016-09-14
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?

Thanks,

E.D.
0
Comment
Question by:edalzell01
4 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 250 total points
ID: 41791758
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.
https://www.mssqltips.com/sqlservertutorial/3305/what-does-begin-tran-rollback-tran-and-commit-tran-mean/

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.
https://www.simple-talk.com/sql/database-administration/handling-errors-in-sql-server-2012/
https://technet.microsoft.com/en-us/library/ms179296(v=sql.105).aspx


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.
https://msdn.microsoft.com/en-CA/library/ms173763.aspx
0
 
LVL 42

Assisted Solution

by:Eugene Z
Eugene Z earned 125 total points
ID: 41793289
it is a very similar to VBA.
..additionally to Rollback (above posts)
you can try
SET XACT_ABORT
/
When SET XACT_ABORT is ON, if a Transact-SQL statement raises a run-time error, the entire transaction is terminated and rolled back.
/
more
https://msdn.microsoft.com/en-us/library/ms188792.aspx
0
 
LVL 49

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 125 total points
ID: 41793846
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.
0
 

Author Closing Comment

by:edalzell01
ID: 41798374
Thanks guys!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question