pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Childs <Blue.Dragon@blueyonder.co.uk>
To: Adam Sherman <adam@tritus.ca>
To: pgsql-sql@postgresql.org
Subject: Re: Constraint Syntax Question
Date: Mon, 12 May 2003 05:47:48 +0100
Message-ID: <200305120547.48775.Blue.Dragon@blueyonder.co.uk> (raw)
In-Reply-To: <7380000.1052691474@saturn>
References: <7380000.1052691474@saturn>

On Sunday 11 May 2003 23:17, Adam Sherman wrote:
> I have a many-to-many relationship between A & B where a B *must* relate to
> at least 1 A but an A may have zero Bs.
>
> How do add this using an ALTER TABLE statement?

	You can't postgres enforces that the foreign key must be unique. so 

ALTER TABLE B ADD CONSTRAINT bafk FOREIGN KEY (key) REFERENCES A(key);

looks like it should work by A(key) must be unique so you will get an error.
I think that this is probably bad database design and you need to get you 
database into 1st normal form hense getting read of any many to many 
relations by removing any many to many relations. Find a good book on 
database design.
	I hope that helps

Peter Childs

>
> Thanks,
>
> A.
>
> --
> Adam Sherman
> Tritus CG Inc.
> http://www.tritus.ca/
> +1 (613) 797-6819
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)




view thread (3+ messages)

Message-ID: <200305120547.48775.Blue.Dragon@blueyonder.co.uk>
Permalink:  ../200305120547.48775.Blue.Dragon@blueyonder.co.uk/
Also on:    postgresql.org/message-id/200305120547.48775.Blue.Dragon@blueyonder.co.uk

 · 

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: Blue.Dragon@blueyonder.co.uk, adam@tritus.ca
  Subject: Re: Constraint Syntax Question
  In-Reply-To: <200305120547.48775.Blue.Dragon@blueyonder.co.uk>

* 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