Solved

How can I rollback a update in SQL Server 2010?

Posted on 2014-01-22
4
302 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

863 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

27 Experts available now in Live!

Get 1:1 Help Now