pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Constraint Syntax Question 3+ messages / 3 participants [nested] [flat]
* Constraint Syntax Question @ 2003-05-11 22:17 Adam Sherman <adam@tritus.ca> 2003-05-12 04:42 ` Re: Constraint Syntax Question Peter and Sarah Childs <peterandsarah@blueyonder.co.uk> 2003-05-12 04:47 ` Re: Constraint Syntax Question Peter Childs <Blue.Dragon@blueyonder.co.uk> 0 siblings, 2 replies; 3+ messages in thread From: Adam Sherman @ 2003-05-11 22:17 UTC (permalink / raw) To: pgsql-sql 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? Thanks, A. -- Adam Sherman Tritus CG Inc. http://www.tritus.ca/ +1 (613) 797-6819 ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Constraint Syntax Question 2003-05-11 22:17 Constraint Syntax Question Adam Sherman <adam@tritus.ca> @ 2003-05-12 04:42 ` Peter and Sarah Childs <peterandsarah@blueyonder.co.uk> 1 sibling, 0 replies; 3+ messages in thread From: Peter and Sarah Childs @ 2003-05-12 04:42 UTC (permalink / raw) To: Adam Sherman <adam@tritus.ca>; 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@postgresql.org) ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Constraint Syntax Question 2003-05-11 22:17 Constraint Syntax Question Adam Sherman <adam@tritus.ca> @ 2003-05-12 04:47 ` Peter Childs <Blue.Dragon@blueyonder.co.uk> 1 sibling, 0 replies; 3+ messages in thread From: Peter Childs @ 2003-05-12 04:47 UTC (permalink / raw) To: Adam Sherman <adam@tritus.ca>; 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@postgresql.org) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-05-12 04:47 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2003-05-11 22:17 Constraint Syntax Question Adam Sherman <adam@tritus.ca> 2003-05-12 04:42 ` Peter and Sarah Childs <peterandsarah@blueyonder.co.uk> 2003-05-12 04:47 ` Peter Childs <Blue.Dragon@blueyonder.co.uk>
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