patternMinor
SQL Server 2008 R2 Restore a back up to a new database
Viewed 0 times
2008newsqldatabasebackserverrestore
Problem
I have a full back up of a database, I want to update some records in some table in the current database from its old backup without affecting other records.
What is the best way to do this?
Basically I want to get some records from the old backup update old values to the current database without doing a restore, what are my options?
What is the best way to do this?
Basically I want to get some records from the old backup update old values to the current database without doing a restore, what are my options?
Solution
You cannot access the records in a database backup without restoring it to a database. You can however restore it to a different database from the one that it was backed up from.
The following link illustrates how to do this using Transact-SQL: http://msdn.microsoft.com/en-us/library/ms190447(v=sql.105).aspx
and in Management studio: http://msdn.microsoft.com/en-us/library/ms177429(v=sql.105).aspx
Then once you have the new database you can write SQL to join the two instances (obviously security considerations will need to be taken into account first). E.g
or similar.
As @Flem mentions you could then use the MERGE statement to merge the two datasets, however you want.
The following link illustrates how to do this using Transact-SQL: http://msdn.microsoft.com/en-us/library/ms190447(v=sql.105).aspx
and in Management studio: http://msdn.microsoft.com/en-us/library/ms177429(v=sql.105).aspx
Then once you have the new database you can write SQL to join the two instances (obviously security considerations will need to be taken into account first). E.g
SELECT Table1.*, Table1_Backup.* FROM Table1
INNER JOIN DB_Restore.dbo.Table1 AS Table1_Backup ON Table1.ID = Table1_Backup.IDor similar.
As @Flem mentions you could then use the MERGE statement to merge the two datasets, however you want.
Code Snippets
SELECT Table1.*, Table1_Backup.* FROM Table1
INNER JOIN DB_Restore.dbo.Table1 AS Table1_Backup ON Table1.ID = Table1_Backup.IDContext
StackExchange Database Administrators Q#31127, answer score: 6
Revisions (0)
No revisions yet.