Re: two primairy key in one table ?

From: Herbert Liechti <Herbert(dot)Liechti(at)thinx(dot)ch>
To: pgsql-general(at)postgresql(dot)org, Angela Luyf <a(dot)c(dot)luyf(at)amc(dot)uva(dot)nl>
Subject: Re: two primairy key in one table ?
Date: 2002-07-05 15:08:35
Message-ID: 3D25B673.1080301@thinx.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 4 Jul 2002, Angela Luyf wrote:

> Hello,
> I have a database model where a many to many relation is used, so i need
> to create a table with two primary key. Don't know how to solve this in
> postgress, can't find it in the tutorials, so can anybody help me with
> this ?

I always create a separate primary key field in the
intermediate table and do a unique index on the
other two fields.

p1.p1Id p2.p2Id
\ /
\ /
\ /
\ t3.t3Id /
t3.p1Id
t3.p2Id

besides of the normal primary and foreign keys I create
an unique index:

create unique index on t3 (p1Id, p2Id);

Regards Herbie
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti http://www.thinx.ch
The content management company. Visit http://www.contentx.ch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Browse pgsql-general by date

  From Date Subject
Next Message Shaun Thomas 2002-07-05 15:11:28 Re: Postgre vs MySQL
Previous Message Marc G. Fournier 2002-07-05 14:27:16 Re: Should next release by 8.0 (Was: Re: [GENERAL] I am