Question about One to Many relationships

Поиск
Список
Период
Сортировка
От Todd Kennedy
Тема Question about One to Many relationships
Дата
Msg-id 226d83de0603240852q54af3512odfce218d69718c8b@mail.gmail.com
обсуждение исходный текст
Ответы Re: Question about One to Many relationships  ("D'Arcy J.M. Cain" <darcy@druid.net>)
Re: Question about One to Many relationships  (Milorad Poluga <milorad.poluga@cores.co.yu>)
Список pgsql-sql
Hi,

This should be a simple idea, but I've been going back and forth on it
with various people in my tech group.

So I've got two tables, one for albums and one for bands, for
simplicity's sake, they look like this:

CREATE TABLE bands (
id serial PRIMARY KEY,
name varchar(64) NOT NULL CHECK( name <> ''),
UNIQUE(name)
);

CREATE TABLE albums (
id serial PRIMARY KEY,
name varchar(128) NOT NULL CHECK( name <> '')
);

And I want to link the band to the album, but, if the album is a
compilation it'll be linked to multiple band.ids, so i can't just add
a column like:

band_id integer REFERENCES band (id)

to the albums table, othewise i'd have to duplicate the albums in the
table (one record for each band associated with an album).

I thought a lookup table would be appropriate here, so like:

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

but i'm being told this is "wrong"

I feel like this is the accurate way to do this, does any one have
experience on this matter?

Thanks!
Todd


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

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