I have two (or more) different databases, identically structured but each containing different data.
How would I go about merging the data of one database into the other? This is a harder problem than I first thought. I have a table with primary keys, so a simple INSERT INTO db1.table1 SELECT * FROM db2.table1 may fail with clashing primary keys.
How can I insert the new records into the end of the table, allowing the identity column to take over and giving me a new primary key, while also cascasding all the foreign keys references?
Is there a better way? I have been looking at bcp but that works on a per table basis and I’m going to lose all my references (ie, table2 won’t know the primary key in table1 has changed so cannot update its foreign key id).
If the idea is that you want to append the records from TableA ind DB1 to TableA in DB2, then that should be fairly easy:
However, it would probably be easier to use the Import Data wizard from SQL2k8 which uses SSIS to pull the data in bulk from one source (in this case: db2.table1) and put it in some destination (in this case: db1.table1).