I mistakenly deleted some rows b , can I recover them back using logs or SSMS
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your database is in simple recovery mode, then you are possibly out of luck. You can restore to the most recent backup, but if it was a long time ago it may not contain copies of the rows you deleted and wish to reinsert. It is also very likely that other data has been inserted in the meantime. You could restore to a new database and then do SQL surgery to get the vanished data back in.
If your database is in full recovery mode, then:
Find the last full backup, any incrementals since then, and all log backup files since the last incremental or full, and restore them up to the correct point in time. You could overwrite your database if that is acceptable, or you can restore to a new database and perform SQL surgery.
The restoration process will look something like this:
Note that I used
WITH STOPAThere, which allows you to restore your database up to a specific point in time. In my example, log backups were taken every 15 minutes, and the fatal query was issued at 1:57:15 AM on 2012-12-09.If you want to restore a database to a new one, you have to do something like this:
Use
RESTORE FILELISTONLYto figure out what’s in the backup. If there are multiple backups in the same file, there’s more syntax to read out that info and then specify which one you want to work with. Usesp_helpdb 'YourDB'to find out where to put your NewDB database and Log files.Then there’s more script to rename the logical files, if you want (which I always do).
Of course, silly me, I’m just realizing now that you could use the SSMS GUI to do most of this. But if you want to start understanding all this stuff and becoming really good at it, I recommend writing the script. I am a developer, but can restore databases lickety-split without having to ask for the “official” DBA’s help.