Subject Re: [firebird-support] merge tables
Author Radu Sky
Ivan Setya Darmawan wrote:
> Hi,
>
> Assume I have 2 branch offices. One at Northpole and the other at
> Southpole (brrbb). Each of them has a same customer table with fields
> like this:
>
> customers
> ----------------------
> cust_id VARCHAR(20)(PK)
> cust_name VARCHAR(80)
>
> And now has come consolidation day. I need to merge northpole customer
> table and southpole customer table to a single customer table in
> headquater database.
>
> I think, using autoincrement for cust_id is not a choice, coz it could
> arise PK constraint error or cust_id replaced with new increment
> value. So, I decide using before insert trigger for cust_id for each
> table (including customers table at headquarter) like this:
>
> BEGIN
> /* Trigger body */
> IF (NEW.CUST_ID IS NULL) THEN
> NEW.CUST_ID = RAND();
> END
>
> and I hope merging those table become visible.
>
> Do I on right track here or anyone has many better ideas?
>
> TIA
> #Ivan Darmawan
>

Hello,

An usual solution to your problem might be that one table PK starts at 1
and the other at 1.000.000.000 or whatever number is comfortable to you.
Other solution is to have one PK as 'A'||<some_generator_value> and the
other as 'B'||<some_generator_value>.

HTH
Radu