Solved

T-SQL - Rollback or Undo Changes

Posted on 2016-09-09
4
37 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 39

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:EugeneZ
EugeneZ 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 46

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now