Subject Re: Can't insert foreign key constraint
Author Alexander V.Nevsky
--- In ib-support@y..., "Carsten Schaefer" <ca_schaefer@g...> wrote:
> Hi,
> i have a table:
> create table T_CH_APOS_ZUORD (
> F_ID_CHARGE INTEGER NOT NULL,
> F_ID_APOS INTEGER NOT NULL
> );
> ALTER TABLE T_CH_APOS_ZUORD
> ADD PRIMARY KEY
> (F_ID_CHARGE,F_ID_APOS);
>
...
>
> 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
> Statement: ALTER TABLE T_CH_APOS_ZUORD
> ADD CONSTRAINT FK_CH_APOS_ZUORD_ID_CHARGE FOREIGN KEY
> (f_id_charge)
> REFERENCES T_CHARGE
> (ID_CHARGE)
> ON UPDATE NO ACTION
> ON DELETE CASCADE

Hi, Carsten. What indexes (system and general) are defined on table
T_CHARGE? If there is 2 indexes

rdb$primaryN (f_id_charge)
and
(
rdb$foreignN (f_id_charge)
or
yourindex (f_id_charge)
)

this is the reason. Indexes that doubles primary or unique used for
new reference often should be dropped before it and re-created after.

Best regards.