How can I rollback an UPDATE query in SQL server 2005?
I need to do this in SQL, not through code.
As already stated there is nothing you can do except restore from a backup. At least now you will have learned to always wrap statements in a transaction to see what happens before you decide to commit. Also, if you don't have a backup of your database this will also teach you to make regular backups of your database.
While we haven't been much help for your imediate problem...hopefully these answers will ensure you don't run into this problem again in the future.
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.
From the information you have specified, your best chance of recovery is through a database backup. I don't think you're going to be able to rollback any of those changes you pushed through since you were apparently not using transactions at the time.
You can use implicit transactions for this
SET IMPLICIT_TRANSACTIONS ON
update Staff set staff_Name='jas' where staff_id=7
ROLLBACK
As you request-- You can SET this setting ( SET IMPLICIT_TRANSACTIONS ON
) from a stored procedure by setting that stored procedure as the start up procedure.
But SET IMPLICIT TRANSACTION ON
command is connection specific. So any connection other than the one which running the start up stored procedure will not benefit from the setting you set.