Composite foreign key - null values
Posted in 1998
We had a strange problem. Obviously our tables are designed with
composite
primary keys, foreign keys in referencing tables are sometimes null
allowed.
Unfortunately we updated several rows with bad (incomplete) FK , we were
surprised
that we could do it without error - RI violation.
So we made some tests
example
table A
column1 PK
column2 PK
column3 PK
table B
column1 null allowed FK --> references table A
column2 null allowed FK
column3 null allowed FK
we run several statements
insert into tableB values (null,"xxxx",null),... etc
even
update tableB set B.column1=null where column2 is not null
without any error.
The last one was the most serious and dangerous it destroyed data.
We were rather confused because we thought that
even incomplete foreign key is considered as referenced value.
Primary key can't be null so FK written in such a way
(part of FK null, the rest not null) must ( we thought)
evoke error -691...missing key in referenced table...
We tested it in Informix On line V 7.20 DSA
Informix On line V 7.22 WGS
Informix On line V 5.01
OS Sinix
primary keys were created in all possible ways
-- create index ... then
alter table ... add constraint primary key
-- alter table ( without previous create index)
-- create index ...
alter table add constraint unique ...
-- alter table add constraint unique ( without explicit. created index)
It seems to be a feature.
We appreciate any information,hints
how RI in Informix works as far as composite foreign key with
several null columns concerned.
katarina
--
Katarina Hamzova Voice : +42 7 5384324
SWH s.r.o Bratislava
Slovakia Katarina.Hamzova@swh.sk