Re: constrains questios ..

From: Johannes Lochmann <johannes(dot)lochmann(at)chello(dot)at>
To: "Matthew Nuzum" <cobalt(at)bearfruit(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: constrains questios ..
Date: 2003-02-11 18:04:14
Message-ID: 200302111904.14268.johannes.lochmann@chello.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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..."

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Wei Weng 2003-02-11 21:26:01 What's wrong with this identification configuration?
Previous Message Matthew Nuzum 2003-02-11 17:41:46 Re: constrains questios ..