Re: Primary and Foreign Key? - Mailing list pgsql-sql

From Russell Simpkins
Subject Re: Primary and Foreign Key?
Date
Msg-id BAY103-F327D058A39D6C120B832E0B5960@phx.gbl
Whole thread Raw
In response to Primary and Foreign Key?  ("Announce" <truthhurts@insightbb.com>)
List pgsql-sql
This is valid ddl to accomplish what you wish.

create table peoplegroups {
peopleid int not null,
groupid int not null,
primary key (peopleid, groupid),
foreign key (peopleid) references people,
foreign key (groupid) references group
}

Check the docs for other options etc.

>From: "Announce" <truthhurts@insightbb.com>
>To: "PostgreSQL SQL List" <pgsql-sql@postgresql.org>
>Subject: [SQL] Primary and Foreign Key?
>Date: Thu, 22 Sep 2005 20:13:35 -0500
>
>I have the following related tables:
>
>PEOPLE
>--------------
>peopleid pkey,
>name,
>etc
>
>
>GROUPS
>-------------
>groupid pkey,
>description,
>etc
>
>
>PEOPLEGROUPS
>-------------------
>peopleid pkey/fkey,
>groupid pkey/fkey
>
>
>What is the CORRECT way (in Postgres) to define the PEOPLEGROUPS table so
>that it has both the double primary key AND still acts as a foreign key for
>people.peopleid and groups.groupid? Can i specify both or is this not
>necessary? Any suggestions would be appreciated.
>
>Thanks!
>
>--
>No virus found in this outgoing message.
>Checked by AVG Anti-Virus.
>Version: 7.0.344 / Virus Database: 267.11.4/109 - Release Date: 9/21/2005
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq




pgsql-sql by date:

Previous
From: "Announce"
Date:
Subject: Primary and Foreign Key?
Next
From: "Stewart Ben (RBAU/EQS4) *"
Date:
Subject: Functions, transactions and RETURN