Re: Question about One to Many relationships

Поиск
Список
Период
Сортировка
От Joe
Тема Re: Question about One to Many relationships
Дата
Msg-id 44243BBA.8030802@freedomcircle.net
обсуждение исходный текст
Ответ на Re: Question about One to Many relationships  ("Todd Kennedy" <todd.kennedy@gmail.com>)
Список 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



В списке pgsql-sql по дате отправления:

Предыдущее
От: "D'Arcy J.M. Cain"
Дата:
Сообщение: Re: Question about One to Many relationships
Следующее
От: george young
Дата:
Сообщение: Re: Custom type