Subject Re: [firebird-support] Re: Foreign key constraint violation
Author Kjell Rilbe
hfsnell wrote:
> Thank for your reply!
> My two table DDL:
[snip]

Well, I tried to clean up your DDL a bit, so we only need to see the
relevant(?) parts:

CREATE TABLE OBJECT_LIST (
OBJECT_ID UVAR31 NOT NULL,
OTYPE_ID DMSMALLINT NOT NULL,
--Several other columns removed for brevity
CONSTRAINT PK_OBJECT_LIST
PRIMARY KEY (OBJECT_ID, OTYPE_ID)
);

--Five foregin keys removed for brevity
--Column description DDL removed for brevity

GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON OBJECT_LIST TO "SYSDBA" WITH GRANT OPTION;


CREATE TABLE OBJECT_BAL (
OBJECT_ID UVAR31 NOT NULL,
OTYPE_ID DMSMALLINT NOT NULL,
--Several other columns removed for brevity
CONSTRAINT PK_OBJECT_BAL
PRIMARY KEY (OBJECT_ID, PERIOD_ID, ACCOUNT_ID, OTYPE_ID)
);

ALTER TABLE OBJECT_BAL
ADD CONSTRAINT FK_OBJECT_BAL_1
FOREIGN KEY (OBJECT_ID, OTYPE_ID)
REFERENCES OBJECT_LIST (OBJECT_ID, OTYPE_ID)
ON UPDATE CASCADE
ON DELETE CASCADE;

--One other foreign key removed for brevity.

GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON OBJECT_BAL TO "SYSDBA" WITH GRANT OPTION;

Now, as I understand, you have ended up with several records in
OBJECT_BAL without a parent record in OBJECT_LIST, thus violating
FK_OBJECT_BAL_1. Is this correct?

I'm hoping one of the experts will join in, but in the meantime I have
one question for you: Is FK_OBJECT_BAL_1 always present/active? Or is it
perhaps temporarily removed at certain operations?

Kjell
--
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64