Subject Re: [ib-support] Fw: Problem creating foreign key
Author Luiz
Graham,
> I have two tables that have a one-to-many relationship. in the child table
I am trying to create a foreign key referencing the parent. When I execute
the DDL the it gives me the following error...
>
> "This operation is not defined for system tables.
> unsuccessful metadata update.
> STORE RDB$REF_CONSTRAINTS failed.
> action cancelled by trigger (1) to preserve data integrity.
> Name of Referential Constraint not defined in constraints table."

> CREATE TABLE SKYSTATUS
> (
> STATUSCODE VARCHAR(5) NOT NULL,
> DESCRIPTION VARCHAR(100) NOT NULL,
>
> PRIMARY KEY (STATUSCODE)
> );
>
> Create Unique Index xSkyStatusDescription on SkyStatus(Description)
>
> CREATE TABLE SKYCLIENTDIARY
> (
> ACCNO VARCHAR(20) NOT NULL,
> DATEOFENTRY TIMESTAMP NOT NULL,
> TIMEOFENTRY VARCHAR(20) NOT NULL,
> CUSER VARCHAR(30),
> CDATE TIMESTAMP,
> CTIME VARCHAR(20),
> ENTRYTYPE VARCHAR(100) NOT NULL,
>
> PRIMARY KEY (ACCNO, DATEOFENTRY, TIMEOFENTRY),
> FOREIGN KEY (EntryType) REFERENCES SkyStatus (Description)
> ON UPDATE CASCADE
> ON DELETE CASCADE
> );
>
> If anyone has any ideas I would appreciate it.
>

You probably have some row(s) in SKYCLIENTDIARY table with the column
EntryType that donĀ“t having a corresponding in table SkyStatus.
You can see if there any rows with this condition using:

select ACCNO, DATEOFENTRY, TIMEOFENTRY from SKYCLIENTDIARY A
where not exists (select 1 from SkyStatus B where A.EntryType=B.Description)

If this query returns some rows, you must have to fix it before apply the FK
constraint.

Regards,
Luiz.