Re: many junction tables

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: E Kolve <ekolve(at)corp(dot)classmates(dot)com>
Cc: Arne Weiner <aswr(at)gmx(dot)de>, pgsql-general(at)postgresql(dot)org
Subject: Re: many junction tables
Date: 2001-09-05 10:06:17
Message-ID: 20010905200616.B7308@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Sep 04, 2001 at 10:22:19AM -0700, E Kolve wrote:
> The idea is this. Suppose I had say 40 or 50 tables like city or
> company (schools, purchases, etc) where I want to have a one to many
> relationship (One person can purchase many things, one person can attend
> many schools) I would have to create many junction tables
> (school_persons, purchase_persons, etc). What I am looking for is a
> solution to creating all these tables, if at all possible.

Well, for one-to-many relationships you don't need separate tables. Only
many-to-many relationships need that. And most of the time a many-to-many
relationship needs more than just the two fields.

For example, students and classes have a many-to-many relationship, but just
a simple two column table is not enough, what you really need it a new
enrolment table which has the two fields and also any other information
related (like grades, etc).

Since you only create the schema once, you can just generate a script to
create them for you. Yes, you'll get a lot of tables, but it's a complex data
structure.

So in the end all you have is one-many relationships.

--
Martijn van Oosterhout <kleptog(at)svana(dot)org>
http://svana.org/kleptog/
> Magnetism, electricity and motion are like a three-for-two special offer:
> if you have two of them, the third one comes free.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Haworth 2001-09-05 10:29:06 Re: Perl won't eval PgSQL boolean value
Previous Message Nico 2001-09-05 08:38:00 plpgsql, fk inherited tables