handling autoincremented primary keys and foreign keys
alias2102
Posts: 2
Hi, I was wondering if "Data Compare" handles foreign keys properly during synchronization. Here's what I mean. I have two databases DB1 and DB2. Each database has a table USERS with autoincremented primary key. This key is also present as a foreign key in another table ORGANIZATION in the same database. Both DB1 and DB2 have both tables present. How would Data Compare merge the data from both databases where primary keys are identical?
Let's say I have a USERS record In DB1 with primary key 1 and a USERS record with the same primary key value in DB2. What is going to happen to the primary keys and their corresponding foreign keys after the merge?
Let's say I have a USERS record In DB1 with primary key 1 and a USERS record with the same primary key value in DB2. What is going to happen to the primary keys and their corresponding foreign keys after the merge?
Comments
What is your desired behavior here? Depending on that you have a couple of options.
If the primary key could be the same for two records that you want to keep, you should set a different comparison key. By default we choose the Primary Key for this, but you can change it, details on how to do so here:
http://documentation.red-gate.com/displ ... to+compare
If, however, the same primary key implies that you only want to overwrite the data in the target machine, simply keeping this row selected in the comparison results when you start the deployment wizard will result in a script which will alter that row.
In either case foreign keys will be respected.
Hopefully that helps, do say if we've misunderstood.
Michael