Solved

How can I rollback a update in SQL Server 2010?

Posted on 2014-01-22
4
304 Views
Last Modified: 2014-01-24
I am new to SQL Server.
Whe update few rows in SQL Server
Eg:
UPDATE EMP
SET State='Tx' WHERE ID=2

How do I rollback the update?
0
Comment
Question by:RajG1978
  • 2
4 Comments
 
LVL 25

Assisted Solution

by:Lee Savidge
Lee Savidge earned 100 total points
ID: 39800445
You need to put it into a transaction

begin tran
UPDATE EMP
SET State='Tx' WHERE ID=2
rollback tran

Open in new window

0
 
LVL 18

Expert Comment

by:x-men
ID: 39800446
restore the database.

rollback ocurres when the transaction is not completed.
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39800465
Of course, I'm assuming you haven't issued the command and wish to undo it? If so, then restore the database from the backup you would have made before doing an update...

If not, then you must live with your update.
0
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 400 total points
ID: 39800466
SQL Server is not Oracle...

In oracle by default the statements will not be commited to the database, so you can issue rollback whenever you want after all the changes that you did.

But SQL Server by default will commit the update to the database as soon as the update finished its job....

So, if you want to rollback such updates you have to put them in an external transaction

BEGIN TRAN
--UPDATE


But if you have accidentally did this update and looking for a way out...
The only option is to do a restore a backup file
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

815 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

12 Experts available now in Live!

Get 1:1 Help Now