Re: Problem with n to n relation - Mailing list pgsql-sql

From Janning Vygen
Subject Re: Problem with n to n relation
Date
Msg-id 0110081030010H.05461@janning
Whole thread Raw
In response to Re: Problem with n to n relation  (Morgan Curley <mcurley@e4media.com>)
Responses Re: Problem with n to n relation  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-sql
Am Freitag,  5. Oktober 2001 14:30 schrieb Morgan Curley:
> just get rid of the serial_id in person2adress -- there is no
> reason for it. Make the pk of that table a composite --> person_id,
> address_id <-- that way you have added some additional integrity to
> your structure. Only one record can exist ffor a given person at a
> given address. However any person can have any number of address
> and any address can have any number of people living at it.

ok fine, i understood it after i figured out what pk means :-)

but how do i reach my goal. It should not be allowed to have a person 
without any address??

janning

> At 12:39 PM 10/5/2001 +0200, Janning Vygen wrote:

> >create table person (
> >  id    serial,
> >  name  text
> >);
> >
> >create table address (
> >  id     serial,
> >  street text
> >  ...
> >);
> >
> >create table person2adress (
> >  id         serial,
> >  person_id  integer not null references person(id),
> >  address_id integer not null references address(id),
> >);
> >
> >than i can select all adresses from one person with id =1 with
> >select street
> >from address
> >where id =
> >  (
> >     select adress_id
> >     from person2adress
> >     where person_id = 1
> >  );
> >
> >ok so far so good. but you can still insert persons without any
> >adress. so its a 0..n relation. But how van i achieve that you
> > can´t insert any person without adress???



pgsql-sql by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: temporary views
Next
From: Bhuvan A
Date:
Subject: How to Return Unique Elements From An Array?