Click here to Skip to main content
15,851,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi every one,please see following queris and give me a solution.


"update emp_table set salary=500000"(Here i failed to give condition ,obviously all record will be updated)

Here i want to do undo any how becouse in this table there is more than Ten thousand records and for different employee there is different salary now accidently i fired the above query ,it puts me in a very big trubble.Please geive me some tricks as soon as possible .

Thanks a lot in advance
Posted
Updated 2-Nov-18 1:53am
v2
Comments
Jim Jos 22-May-12 5:57am    
You won't be able to undo as it is.. Have you got auditing feature enabled you ll have all the previous values there.. You need to update your table from the audit table.
kunalkumarsingh 22-May-12 8:46am    
i dont have any idea about auditing feature will you please tell me how to do it from audit table?

Thanks in advance
ssd_coolguy 22-May-12 6:00am    
if you have backup file then you can restore you table with values..

If you have already executed the statement without transaction, it's committed to the database. In that case, you can restore the database to a previous situation.

However, if you do that, you may loose modifications that are made after the backup. So One possibility is that you restore the backup to a whole new SQL server database (or even instance) and then using that database fetch all the original values from the table and put them in place in your actual table.
 
Share this answer
 
Comments
Bernhard Hiller 23-May-12 3:52am    
From the information the OP gave us, I conclude that that's the best way to do: the query has been committed, auditing does not exist. This way he'll come closest to the correct state of the data. Hopefully, a (recent) backup is available...
You can use transactions for this :
SQL
begin tran
update emp_table set salary=500000

select * from emp_table

-- rollback tran
-- commit tran

You can do the testing with the above and if everything is ok use the commit tran else rollback tran
 
Share this answer
 
If you have back up of previous data restore it.
You can roll back only transactions not query without transaction.
 
Share this answer
 
Its always best to run queries in a transaction so that you can rollback at anytime required.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900