Solved

How can I rollback a update in SQL Server 2010?

Posted on 2014-01-22
4
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

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…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

742 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