Subject | Can't insert foreign key constraint |
---|---|
Author | Carsten Schaefer |
Post date | 2001-10-07T13:53:55Z |
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);
Now i want to add a foreign key constraint to it (t_charge has id_charge as primary key):
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;
I get the following error from ibconsole:
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
But this is wrong. When i do the following query:
select * from t_ch_apos_zuord where f_id_charge not in (select distinct id_charge from t_charge)
i get no result.
Why can i not add the contstraint ?
(on another DB with different (less) data it works !)
I'm using Firebird B448 on Win2KSP2.
gruse
Carsten
[Non-text portions of this message have been removed]
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);
Now i want to add a foreign key constraint to it (t_charge has id_charge as primary key):
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;
I get the following error from ibconsole:
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
But this is wrong. When i do the following query:
select * from t_ch_apos_zuord where f_id_charge not in (select distinct id_charge from t_charge)
i get no result.
Why can i not add the contstraint ?
(on another DB with different (less) data it works !)
I'm using Firebird B448 on Win2KSP2.
gruse
Carsten
[Non-text portions of this message have been removed]