"Max Power" <Ma*******@excelence.co.uk> wrote in message
news:bu**********@sparta.btinternet.com...
Hi All:
Being a bit of a nube to MSSQL I could use a little advice. This is the
situation.
A client's HDD became full so I backed up, deleted then recreated a blank
database (they said they didn't need the stored data).
They have now deceided that they want the data again.
My plan is to restore the database to a second volume so it can grow as
much as is needed, however, there is now data in the second instance that would
need importing to the restored DB.
I can restore the backed up db with a different name and reconfigure the
software that accesses it but what would be the best method to append the
restored DB with the data in the current instance of said DB? Both DBs are
identical.
TIA
MP
There's no generic way to 'merge' two databases, but as a very general
approach, you can do something like this for each table:
insert into DestinationDB.dbo.Table1 (col1, col2, ...)
select col1, col2, ...
from SourceDB.dbo.Table1 s
where not exists (select * from DestinationDB.dbo.Table1 d
where d.PrimaryKeyColumn = s.PrimaryKeyColumn)
But there are potential issues - foreign keys mean you have to populate the
tables in the correct order (or disable them during load), and if tables are
using IDENTITY columns or other artificial keys, then you might exclude
valid data. You also might be able to exclude tables which hold static data
such as countries and currencies.
Simon