pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Morgan Curley <mcurley@e4media.com>
To: pgsql-sql@postgresql.org
Subject: Re: Problem with n to n relation
Date: Fri, 05 Oct 2001 08:30:54 -0400
Message-ID: <5.0.2.1.0.20011005082745.0273b430@mail.e4media.com> (raw)
In-Reply-To: <0110051239400B.30993@janning>

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

Morgan
At 12:39 PM 10/5/2001 +0200, Janning Vygen wrote:
>Hi,
>
>i create n to n relations like this, right?
>
>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???
>
>thanks in advance
>janning
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster 

-------------
Morgan Curley
Partner, e4media
mcurley@e4media.com 
917 751 8328
http://www.e4media.com
-------------------------




view thread (9+ messages)  latest in thread

Message-ID: <5.0.2.1.0.20011005082745.0273b430@mail.e4media.com>
Permalink:  ../5.0.2.1.0.20011005082745.0273b430@mail.e4media.com/
Also on:    postgresql.org/message-id/5.0.2.1.0.20011005082745.0273b430@mail.e4media.com

 · 

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: mcurley@e4media.com
  Subject: Re: Problem with n to n relation
  In-Reply-To: <5.0.2.1.0.20011005082745.0273b430@mail.e4media.com>

* 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