X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 15E13474E53 for ; Tue, 11 Feb 2003 12:59:25 -0500 (EST) Received: from viefep13-int.chello.at (viefep13-int.chello.at [213.46.255.15]) by postgresql.org (Postfix) with ESMTP id D65FD474E5C for ; Tue, 11 Feb 2003 12:59:23 -0500 (EST) Received: from gimli.auenland.local ([213.47.228.41]) by viefep13-int.chello.at (InterMail vM.5.01.05.17 201-253-122-126-117-20021021) with ESMTP id <20030211175921.UKOA18878.viefep13-int.chello.at@gimli.auenland.local>; Tue, 11 Feb 2003 18:59:21 +0100 Content-Type: text/plain; charset="iso-8859-1" From: Johannes Lochmann To: "Matthew Nuzum" , Subject: Re: constrains questios .. Date: Tue, 11 Feb 2003 19:04:14 +0100 User-Agent: KMail/1.4.3 References: <004e01c2d1f4$d9546f50$6900a8c0@mattspc> In-Reply-To: <004e01c2d1f4$d9546f50$6900a8c0@mattspc> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200302111904.14268.johannes.lochmann@chello.at> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/222 X-Sequence-Number: 11620 On Tuesday 11 February 2003 18:41, Matthew Nuzum wrote: > Can you please demonstrate the syntax you would use to create the > constraints? I'm not real clear on this and my attempts haven't > produced what I wanted. Checked the docs? They are really good at this point. Anyways. The following creates Tables A, B and AB. A and B have an id and a text fie= ld,=20 AB connects them (N:M relation). create table A ( id integer not null primary key, something varchar(16) ); create table B ( id integer not null primary key, otherthing varchar(16) ); create table AB ( id_a integer not null, id_b integer not null, constraint pk_AB primary key(id_a, id_b) ); create unique index u_A_something on A (something); create unique index u_A_otherthing on B (otherthing); alter table AB add constraint fk_AB_A_exists foreign key(id_a) references= =20 A(id); alter table AB add constraint fk_AB_B_exists foreign key(id_b) references= =20 B(id); HTH Johannes Lochmann --=20 Disclaimer - These opiini^H^H damn! ^H^H ^Q ^[ .. :w :q :wq :wq! ^d X^? exit X Q ^C ^c ^? :quitbye CtrlAltDel ~~q :~q logout save/quit :!QUIT ^[zz ^[ZZZZZZ ^H man vi ^@ ^L ^[c ^# ^E ^X ^I ^T ? help helpquit ^D ^d man help ^C exit ?Quit ?q CtrlShftDel "Hey, what does this button d..."