Subject Re: [firebird-support] Foreign Key violation on restore
Author Urs Liska
flashjobs schrieb:
>
>
> Hello!
>
> I have a database in FirebirdSS-1.0.3.972-0
>
> when i tried to restore this database, i cannot restore, one foreign
> key violation error is coming, but the database is working perfectly
>
> i have identified that there is invalid data in foreign key column
> defined table.
>
> 1) How these problems are coming?
> 2) Can we restore such a database ?
>
> when i trying to restore the database only i can understand there is
> a problem.
>
>
> Regards
> Manoj

Do you by chance have self joined tables (i.e. tables referencing itself)?
For example you can have a table with words and one field referencing
another word as the base form of a "family".
CREATE TABLE WORD
ID BIGINT,
WORD VARCHAR(30),
WORD_ID BIGINT

with ID being the primary key and WORD_ID referencing WORD.ID.

In such a case you can INSERT only records referencing an existing
record (i.e. a record that has been inserted earlier).
But you can UPDATE a record to reference a record that has been inserted
later.
When you restore such a thing firebird tries to INSERT a record that
references a record that doesn't exist yet - which causes a foreign key
violation.

HTH
Urs