Subject Re: [firebird-support] Problem with foreign key
Author Helen Borrie
At 03:28 PM 28/04/2005 +1000, Grant Brown wrote:
>HI all,
>
>When I run the following stored procedure I keep getting a foreign key
>violation.
>
>HEAD_ID is the value that links as the FK to another table
>
>Now I have checked that the value being passed as :HEAD does in fact
>exist in the master table.

Apparently not. :-)


>Can anyone tell me why this is causing such a violation ?

Was the master record created in another transaction that your current
transaction can't see?


>-------- stored procedure -------
>
> tmpid = GEN_ID(GEN_PK_KEY_FEAT_ID, 1);
> insert into BUS_KEY_FEAT(HEAD_ID, DETECT_ID, DATATYPE, K_ITEM_ID)
> values (:HEAD, :tmpid, :DT, :ITEM_NO);
>
>-------- foreign Key -------
>
>ALTER TABLE BUS_KEY_FEAT ADD CONSTRAINT FK_BUS_KEY_FEAT_ID
> FOREIGN KEY (HEAD_ID) REFERENCES BUSDETAILS
> (DETECTID)
> ON DELETE CASCADE
> ON UPDATE NO ACTION;

./hb