Re: Constraint Syntax Question

From: Peter and Sarah Childs <peterandsarah(at)blueyonder(dot)co(dot)uk>
To: Adam Sherman <adam(at)tritus(dot)ca>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Constraint Syntax Question
Date: 2003-05-12 04:42:27
Message-ID: 200305120542.27498.peterandsarah@blueyonder.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)postgresql(dot)org)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Childs 2003-05-12 04:47:48 Re: Constraint Syntax Question
Previous Message Chris Linstruth 2003-05-12 01:05:06 Re: sub select performance