• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

How can I rollback a update in SQL Server 2010?

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
RajG1978
Asked:
RajG1978
  • 2
2 Solutions
 
Lee SavidgeCommented:
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
 
x-menIT super heroCommented:
restore the database.

rollback ocurres when the transaction is not completed.
0
 
Lee SavidgeCommented:
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
 
Surendra NathTechnology LeadCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now