Subject Foreign key violation
Author Gabriel Juncu
Hi List,

I'm using Firebird 1.0.2 W32 and I'm having the following problem:

2 tables:

Country:
CREATE TABLE COUNTRY (
ID NUMERIC(18,0) NOT NULL,
NAME VARCHAR(50))

ALTER TABLE COUNTRY ADD CONSTRAINT PK_COUNTRY PRIMARY KEY (ID);

and Region:
CREATE TABLE REGION (
ID NUMERIC(18, 0) NOT NULL,
NAME VARCHAR(50),
COUNTRY_ID NUMERIC(18, 0));

ALTER TABLE REGION ADD CONSTRAINT PK_REGION PRIMARY KEY (ID);
ALTER TABLE REGION ADD CONSTRAINT FK_REGION_COUNTRY FOREIGN KEY (COUNTRY_ID) REFERENCES COUNTRY (ID);

Nothing unusual yet, but after the following instructions:

Start Transaction 1 and execute:
UPDATE COUNTRY SET NAME = NAME where ID = 13;

if I start Transaction 2 and execute:
INSERT INTO REGION (ID, NAME, COUNTRY_ID) VALUES (1, 'SOME REGION NAME', 13)
before commiting Transaction 1, I get the 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_REGION_COUNTRY" on table "REGION".

Both transactions are READ COMMITED, REC VERSION.

Well, my question is: why I get this error, since the country with
ID=13 exists in database?

Best regards,
Gabriel Juncu