| From: | Itai Zukerman <zukerman(at)math-hat(dot)com> |
|---|---|
| To: | Andreas Tille <tillea(at)rki(dot)de> |
| Cc: | PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: Foreign key problem |
| Date: | 2001-06-25 14:07:21 |
| Message-ID: | 878zig1wme.fsf@matt.w80.math-hat.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Je Mon, 25 Jun 2001 09:34:01 +0200 (CEST),
Andreas Tille <tillea(at)rki(dot)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, however Postgres
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/>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Luis Sousa | 2001-06-25 15:08:44 | Problems using a rule with the WHERE clause |
| Previous Message | Christof Glaser | 2001-06-25 14:06:48 | Re: Foreign key problem |