Deepak writes "SQL Team, Accidently i have executed delete command on my db without specifying the year and it deleted all the data . query is mentioned below:
delete from game_type1 where facility_id in(select facility_id from facility_details where facility_name='Madill GC' or facility_name='Goldsby GC') and month(convert(varchar(10), data_date, 101))=9
Is there any way that i can recover the deleted data and restore it again. It will be a great help for me . It can save my job.
For you and anyone else that has access to production data and needs to perform deletes and update statements directly on that production data, here are a couple tips:
1. write the DELETE or UPDATE statement but before you execute it, change the command to SELECT. Look at the selected results and confirm they are only the rows you want to change.
2. issue a BEGIN TRAN before the statement, confirm the results then issue either a COMMIT or ROLLBACK accordingly. Keep in mind that while the transaction is open you may be blocking access to those tables/rows.
3. (this should really be number 1) Hopefully you have a development/qc environment that developers only have access to. The statements can be run there first then after successfull verification, submit the script to an Operations/DBA person who is one of the few people with access to production servers for them to run.