How can I rollback an UPDATE query in SQL server 2005?

Guddu picture Guddu · Apr 6, 2009 · Viewed 156.4k times · Source

How can I rollback an UPDATE query in SQL server 2005?

I need to do this in SQL, not through code.

Answer

Adam Robinson picture Adam Robinson · Apr 6, 2009
begin transaction

// execute SQL code here

rollback transaction

If you've already executed the query and want to roll it back, unfortunately your only real option is to restore a database backup. If you're using Full backups, then you should be able to restore the database to a specific point in time.