I have a table that needs to merge from same table in another database.
Condition is one of the column in composite primary key is generated by sequence and may differ in another database.
How can we sync remaining columns in this situation?
Ex.
DB1:
Table: SRE_SERVICE_OPTION
Columns:(OPTION_SET_ID, OPTION_NAME, OPTION_VALUE, VALUE_ORDER)
DB2:
Table: SRE_SERVICE_OPTION
Columns:(OPTION_SET_ID, OPTION_NAME, OPTION_VALUE, VALUE_ORDER)
Primary key:
OPTION_SET_ID, OPTION_NAME, VALUE_ORDER
How should I write merge statement?
You’ve made the classic error in a distributed database. Simply put, by using two separate sequences you have an inconsistent primary key across the tables. You will only be able to use MERGE if your tables are both separately unique on
OPTION_NAME,OPTION_VALUEandVALUE_ORDER.Your only other hope is that your tables do not contain any duplicated information between them. If so you can simply insert from one into the other.
Otherwise, you are, I’m afraid out of luck. I would re-design your database so that it’s impossible to send duplicated information into two different tables with separate, inconsistent, surrogate keys.