I have two databases with identical schemas. Each is used by the same application to run a document archiving system for two different companies.
Both companies have been acquired by a third company that wishes to merge the databases into a single database and operate as a single company.
In general all primary keys are called ID and are INT IDENTITY columns and most of the values overlap between the two databases.
I have a broad plan as to how to attack this problem:
1. One of the databases (DB1) will not be altered
2. Identify all cases where the ID values for each table overlap
3. Define an offset to the value of the ID in the 2nd database (DB2) that will take it well beyond the current highest value in DB1
4. Add these offsets to the ID values and all the foreign keys that refer to them in a test copy of DB2
5. Verify that the test copy of DB2 still operates correctly and fix any problems
6. Merge the test copy of DB2 with a test copy of DB1 and verify that the merged database now supports both companies' data correctly
7. Apply the process defined in step 4 to the live DB2 and allow it to run live unmerged for a period to be sure that all problems have been found
8. Finally merge the live versions of DB1 and DB2
This is a much simplifed version of what I will actually have to do but I am seeking advice as to whether this is the best approach and whether there are any tools available to assist.
I am particularly concerned as to the best way of doing steps 4 and 6 as foreign key contraints can make this very tricky. I am quite tempted to dump out all the data to flat files using bcp, adjust the values there and then bulk load all the data back into an empty database but I would appreciate any thoughts on this matter.
I'm not necessarily looking for a SQL only solution. I am quite happy to write utility applications to actually do the some of the work, unless someone can point me at some tools that will do the job for me.
Bob Boffin
Both companies have been acquired by a third company that wishes to merge the databases into a single database and operate as a single company.
In general all primary keys are called ID and are INT IDENTITY columns and most of the values overlap between the two databases.
I have a broad plan as to how to attack this problem:
1. One of the databases (DB1) will not be altered
2. Identify all cases where the ID values for each table overlap
3. Define an offset to the value of the ID in the 2nd database (DB2) that will take it well beyond the current highest value in DB1
4. Add these offsets to the ID values and all the foreign keys that refer to them in a test copy of DB2
5. Verify that the test copy of DB2 still operates correctly and fix any problems
6. Merge the test copy of DB2 with a test copy of DB1 and verify that the merged database now supports both companies' data correctly
7. Apply the process defined in step 4 to the live DB2 and allow it to run live unmerged for a period to be sure that all problems have been found
8. Finally merge the live versions of DB1 and DB2
This is a much simplifed version of what I will actually have to do but I am seeking advice as to whether this is the best approach and whether there are any tools available to assist.
I am particularly concerned as to the best way of doing steps 4 and 6 as foreign key contraints can make this very tricky. I am quite tempted to dump out all the data to flat files using bcp, adjust the values there and then bulk load all the data back into an empty database but I would appreciate any thoughts on this matter.
I'm not necessarily looking for a SQL only solution. I am quite happy to write utility applications to actually do the some of the work, unless someone can point me at some tools that will do the job for me.
Bob Boffin