X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2BFA7D830F for ; Thu, 22 Sep 2005 22:34:11 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 88660-02 for ; Fri, 23 Sep 2005 01:34:05 +0000 (GMT) Received: from hotmail.com (bay103-f32.bay103.hotmail.com [65.54.174.42]) by svr1.postgresql.org (Postfix) with ESMTP id C4080D6E69 for ; Thu, 22 Sep 2005 22:34:06 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Thu, 22 Sep 2005 18:34:11 -0700 Message-ID: Received: from 65.54.174.206 by by103fd.bay103.hotmail.msn.com with HTTP; Fri, 23 Sep 2005 01:34:11 GMT X-Originating-IP: [65.54.174.206] X-Originating-Email: [russellsimpkins@hotmail.com] X-Sender: russellsimpkins@hotmail.com In-Reply-To: From: "Russell Simpkins" To: truthhurts@insightbb.com, pgsql-sql@postgresql.org Subject: Re: Primary and Foreign Key? Date: Thu, 22 Sep 2005 21:34:11 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 23 Sep 2005 01:34:11.0311 (UTC) FILETIME=[E60BDFF0:01C5BFDE] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.942 required=5 tests=[AWL=0.192, DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376, MSGID_FROM_MTA_HEADER=0] X-Spam-Level: * X-Archive-Number: 200509/220 X-Sequence-Number: 22767 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" >To: "PostgreSQL SQL List" >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