Merging Two Firebird Databases

There is no simple way to merge 2 databases without having to verify the contents of the final database file. The end-user needs to understand that there might be duplicate records for some patients, although they will have non-duplicate fitting sessions. Here are the steps to achieve the merging. You need to use IBExpert or some other tool that will execute SQL and connect with the Firebird database system.

Algorithm for Merging
Prepare Source Database Records for Exporting

Renumber patient records in source database:

USE mergesrc
 
/* set all records to uppercase */
UPDATE patient
  SET firstname = UPPER(firstname), lastname = UPPER(lastname);
 
/* Renumber patient records */
UPDATE patient 
  SET patientno = patientno+100;
 
COMMIT;
Export Records

Export data as a set of INSERT operators:

/*
 * Export data into SQL script as a set of INSERT operators 
 */
 
/* export PATIENT and FITTING records first */
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO patient;
SELECT * FROM patient;
 
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO fitting;
SELECT * FROM fitting;
 
/* export product records now */
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO agco;
SELECT * FROM agco;
 
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO eq2;
SELECT * FROM eq2;
 
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO eq3;
SELECT * FROM eq3;
 
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO foundation;
SELECT * FROM foundation;
 
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO instinct;
SELECT * FROM instinct;
 
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO nueve;
SELECT * FROM nueve;
 
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO paragon2;
SELECT * FROM paragon2;
 
OUTPUT 'C:\TEMP\data.sql' ASINSERT INTO paragon4;
SELECT * FROM paragon4;
 
OUTPUT;
Import Records into Target Database
USE mergetarget
INPUT 'C:\TEMP\data.sql';