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).