Subject Re: How to turn referential integrity checking off
Author pifproject
Hello Roman,
thank you very much indeed again for your helpful replies!

>> My purpose is to find a way to populate a target Firebird
>> database without having problems with referenced tables
>> that still do not exist (because they're not written
>> to the database at that point in time).
> I think you mean that data in the tables do not exist, not
> the tables themselves. Right?

The problems result during the creation of the tables themselves. If a
CREATE TABLE statement has a "REFERENCES 'primaryKeyTableName'
('primaryKeyTableColumn')" clause and that 'primaryKeyTable' has not
been created yet, such a CREATE TABLE statement will cause an error
because both the referenced table and its respective column cannot be
found in the target database at that time. I first create a table,
then populate it (write data into that created table), afterwards
create another table and populate it and so on until there are tables
to write to the database and data for the tables to populate them with.

> this functionality does not exist, as well as the deferred
> constraint checking. You can walk through all tables, get
> their constraints with DatabaseMetaData call (getImportedKeys
> and getExportedKeys), store somewhere, and at the end construct
> appropriate SQL statements.

I have already constructed parts of the SQL statements with the help
of those methods.

> When gbak creates a backup file, it stores the constraints
> separately as ALTER TABLE ... ADD CONSTRAINT statements

I have got the idea to construct such ALTER statements, ignore
initially the REFERENCES parts when creating the tables, then execute
these ALTER statements when all tables have already been created and
their data written in the target database. This may well solve my
problem in a optimal way.