Sign in to follow this  
graveyard filla

Best way to do this? (DB related)

Recommended Posts

Hi, I am using MS SQL. Recently I deleted a bunch of rows from a table, but before doing so backed up the database. Now, a few days later, it turns out I want to restore those rows from that able that I deleted. However we can't just simply roll-back the DB to the restore point, as new data has been added since then. So, what is the easiest way to grab all the data from the one table in the backed up DB, and copy that into the current DB? I have no clue on how to do this.. The only way I can think of is: -copy the old .mdf and .ldf files from the backed up DB -attach the database to a different named DB -do something like insert into table(foo,bar) values(select 'foo' from other_database.table,select bar from other_database.table) However, this won't work for several reasons. First of all, the backup of the DB is NOT just a copy of the raw .mdf and .ldf file, but rather a backup made using Enterprise Manager... second of all, obviously that insert / select statement won't work as is... Thanks a lot for any help.

Share this post

Link to post
Share on other sites
How I would do it:

1. Restore backup into a new database
2. Make duplicate of live database to merge with
3. Do the copy as you said ... insert into Duplicate_Database.whatever ... where Earlier_Delete_Criteria
4. Verify that it actually restored the lines you wanted. If it didn't, drop the duplicate database and restart from step two.
5. Stop live use of the database, if reasonable and proper for the situation
6. Back up live database again
7. Begin a transaction
8. Do the insert that worked proplery in step 4
9. Verify that the results are correct. If it failed, rollback and start over. If it worked, commit the transaction.
10. Resume live use of the database, if stopped in step 5.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this