not sure about constraints

From: Jerome Alet <alet(at)librelogiciel(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: not sure about constraints
Date: 2005-09-02 13:23:56
Message-ID: 20050902132356.GD10284@mail.librelogiciel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

I've got 4 tables :

CREATE TABLE tableA (id SERIAL PRIMARY KEY NOT NULL,
blahA TEXT);

CREATE TABLE tableB (id SERIAL PRIMARY KEY NOT NULL,
blahB TEXT);

CREATE TABLE tableC (id SERIAL PRIMARY KEY NOT NULL,
ida INT4 REFERENCES tableA(id),
idb INT4 REFERENCES tableB(id),
blahC TEXT);

CREATE TABLE tableD
(id SERIAL PRIMARY KEY NOT NULL,
ida INT4,
idb INT4,
blahC TEXT,
CONSTRAINT checkAB FOREIGN KEY (ida, idb) REFERENCES tableC(ida, idb));

Is the definition of tableD sufficient, or should I do it this way
instead :

CREATE TABLE tableD
(id SERIAL PRIMARY KEY NOT NULL,
ida INT4 REFERENCES tableA(id),
idb INT4 REFERENCES tableB(id),
blahD TEXT,
CONSTRAINT checkAB FOREIGN KEY (ida, idb) REFERENCES tableC(ida, idb));

which looks superfluous to me.

???

Thanks in advance

Jerome Alet

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2005-09-02 13:43:15 Re: not sure about constraints
Previous Message Michael Fuhr 2005-09-02 13:12:11 Re: cursor "<unnamed portal 1>" already in use