问题
How can I represent an Album entity which can be vinyl and/or cd and/or tape. I assume those can't be declared as subtypes of the Album entity as there would be no way the album could be all of them. Should it be a multivalue attribute of the Album entity? Also each type vinyl, cd, tape have different attributes (eg. vinyl might have colour, cd might have an associated video clip etc.)
And for an Artist entity how could I make a solo artist and a group artist? At the minute I have an Artist entity with subtypes of Solo (with more attributes) and Group (with a multivalue attribute of artists.)
I have put a relationship between Solo and Group (MemberOf) which is 1 Solo to Many Groups.
Is this correct or should I make it different?
Thanks
回答1:
I would probably start with something like this and then adapt it based on other needs:
albums
id unsigned int(P)
name varchar(100)
artist_id unsigned int(F artists.id)
released date
...
+----+------------------+-----------+------------+-----+
| id | name | artist_id | released | ... |
+----+------------------+-----------+------------+-----+
| 1 | ...But Seriously | 1 | 1989-11-07 | ... |
| 2 | Invisible Touch | 2 | 1986-06-09 | ... |
| 3 | Heaven and Hell | 3 | 1980-04-25 | ... |
| .. | ................ | ......... | .......... | ... |
+----+------------------+-----------+------------+-----+
artists
id unsigned int(P)
name varchar(50)
...
+----+------------------+
| id | name |
| 1 | Phil Collins |
| 2 | Genesis |
| 3 | Black Sabbath |
| 4 | Ronnie James Dio |
| 5 | Dio |
| 6 | Mike Rutherford |
| .. | ................ |
+----+------------------+
artists_artists
id unsigned int(P)
artist_id unsigned int(F artists.id)
group_id unsigned int(F artists.id)
+----+-----------+----------+
| id | artist_id | group_id |
+----+-----------+----------+
| 1 | 1 | 2 |
| 2 | 4 | 3 |
| 3 | 4 | 5 |
| 4 | 6 | 2 |
| .. | ......... | ........ |
+----+-----------+----------+
cds
id unsigned int(P)
album_id unsigned int(F albums.id)
...
+----+----------+-----+
| id | album_id | ... |
+----+----------+-----+
| 1 | 1 | ... |
| 2 | 2 | ... |
| .. | ........ | ... |
+----+----------+-----+
colours
id unsigned int(P)
name varchar(20)
+----+------+
| id | name |
+----+------+
| 1 | Red |
| 2 | Blue |
| .. | .... |
+----+------+
tapes
id unsigned int(P)
album_id unsigned int(F albums.id)
...
+----+----------+-----+
| id | album_id | ... |
+----+----------+-----+
| 1 | 1 | ... |
| 2 | 2 | ... |
| .. | ........ | ... |
+----+----------+-----+
vinyls
id unsigned int(P)
album_id unsigned int(F albums.id)
colour_id unsigned int(F colours.id)
...
+----+----------+-----------+-----+
| id | album_id | colour_id | ... |
+----+----------+-----------+-----+
| 1 | 1 | 1 | ... |
| 2 | 1 | 2 | ... |
| 3 | 3 | 3 | ... |
| .. | ........ | ......... | ... |
+----+----------+-----------+-----+
来源:https://stackoverflow.com/questions/19437686/entity-relationship-diagram-entity-which-can-have-multiple-types