Subject Re: problem with foreign keys
Author Alexander V.Nevsky
--- In firebird-support@yahoogroups.com, "Rodrigo Bravo"
<rodrigobravo@v...> wrote:
> Hi,
> I've a problem with Firebird 1.5 Final Release:
> PREVIOUS STATUS:
> TABLEA:
> ------------------------
> ID | DESCRIPTION
> ------------------------
>
> TABLEB:
> ----------------------------------
> ID | ID_FK | DESCRIPTION
> -----------------------------------
> Important: On TABLEB exists a Foreign Key, between TABLEB.ID_FK and
TABLEA.ID
>
> STEP 1 on TransactionA:
> Execute the sql: "SELECT * FROM TABLEA WHERE A_ID = 1"
>
> STEP 2 on TransactionB:
> Execute the sql: "INSERT INTO TABLEB (ID, ID_FK, DESCRIPTION) VALUES (1,
> 1, "Hello")"
>
> And the last command returns this error:
> Unsuccessful execution caused by system error that does not preclude
successful
> execution of subsequent statements lock conflict on no wait transaction.
> violation of FOREIGN KEY constraint "FK_XXXX" on table "TABLEB"
>
> Does anyone knows why I can't insert the last record?

Many reasons. Firstly, does STEP 1 returned row from TABLEA? If not
- answer is obvious, there is'nt parent record for record inserted
into TABLEB. If yes - this is transactions control and isolation level
question. If parent record inserted but not commited, TransactionB
will not see it in any case. If it is commited but TransactionB have
concurrency isolation level and commit of parent record was performed
after start of TransactionB, it will never see this record.

Best regards,
Alexander