pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Johannes Lochmann <johannes.lochmann@chello.at>
To: Matthew Nuzum <cobalt@bearfruit.org>
To: pgsql-sql@postgresql.org
Subject: Re: constrains questios ..
Date: Tue, 11 Feb 2003 19:04:14 +0100
Message-ID: <200302111904.14268.johannes.lochmann@chello.at> (raw)
In-Reply-To: <004e01c2d1f4$d9546f50$6900a8c0@mattspc>
References: <004e01c2d1f4$d9546f50$6900a8c0@mattspc>

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




view thread (3+ messages)

Message-ID: <200302111904.14268.johannes.lochmann@chello.at>
Permalink:  ../200302111904.14268.johannes.lochmann@chello.at/
Also on:    postgresql.org/message-id/200302111904.14268.johannes.lochmann@chello.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: johannes.lochmann@chello.at, cobalt@bearfruit.org
  Subject: Re: constrains questios ..
  In-Reply-To: <200302111904.14268.johannes.lochmann@chello.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox