Re: constrains questios .. - Mailing list pgsql-sql

From Johannes Lochmann
Subject Re: constrains questios ..
Date
Msg-id 200302111904.14268.johannes.lochmann@chello.at
Whole thread Raw
In response to Re: constrains questios ..  ("Matthew Nuzum" <cobalt@bearfruit.org>)
List pgsql-sql
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 field,
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
A(id);
alter table AB add constraint fk_AB_B_exists foreign key(id_b) references
B(id);

HTH

Johannes Lochmann

--
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..."



pgsql-sql by date:

Previous
From: "Matthew Nuzum"
Date:
Subject: Re: constrains questios ..
Next
From: "James Cooper"
Date:
Subject: anal about my syntax