Je Mon, 25 Jun 2001 09:34:01 +0200 (CEST),
Andreas Tille <tillea@rki.de> scribis:
> CREATE TABLE ResKulturDetail
> (
> IdLabNr int,
> IdIndex smallint
> );
>
> CREATE TABLE ResKulturDetailDay
> (
> IdLabNr int,
> IdIndex smallint
> );
>
> CREATE INDEX IX_IdLabNr_KulturDetail ON ResKulturDetail(IdLabNr) ;
>
> ALTER TABLE ResKulturDetailDay ADD CONSTRAINT FK_ResKulturDetailDay
> FOREIGN KEY (IdLabNr,IdIndex)
> REFERENCES ResKulturDetail (IdLabNr,IdIndex) ;
> Can anybody explain, why the foreign key constraint fails?
According to the documentation for CREATE TABLE:
In addition, the referenced columns are supposed to be the columns of a UNIQUE constraint in the referenced table,
howeverPostgres does not enforce this.
Well, it looks like PostgreSQL *does* enforce it. Try it with:
CREATE UNIQUE INDEX IX_IdLabNr_KulturDetail ON ResKulturDetail(IdLabNr, IdIndex) ;
I'm not sure why this restriction is necessary...
--
Itai Zukerman <http://www.math-hat.com/~zukerman/>