Re: Question about One to Many relationships

From: Joe <svn(at)freedomcircle(dot)net>
To: Todd Kennedy <todd(dot)kennedy(at)gmail(dot)com>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Question about One to Many relationships
Date: 2006-03-24 18:34:34
Message-ID: 44243BBA.8030802@freedomcircle.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Todd Kennedy wrote:
> They haven't responded me as of yet. There should be a band associated
> with each album -- this is handled in code, but other than that this
> is the only relational db way I can think of to do it.

But if a band can have songs in many albums and an album can have songs
from multiple bands, it's a many-to-many relationship, NOT one-to-many.
Short of the full track design suggested by PFC, you'd normally
implement a many-to-many table as follows:

CREATE TABLE bands_on_album (
band_id integer REFERENCES band (id),
album_id integer REFERENCES albums (id),
PRIMARY KEY (band_id, album_id)
)

This of course precludes the same band being listed twice in a given
album. If you do need that info, then you're really asking for "tracks".

Joe

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Todd Kennedy 2006-03-24 18:36:44 Re: Question about One to Many relationships
Previous Message Julie Robinson 2006-03-24 17:50:57 Re: SQL Query Newbie Help