实体关系图 - 可以有多种类型的实体

时间:2013-10-17 21:31:03

标签: database-design entity-relationship relationship

如何表示可以是乙烯基和/或CD和/或磁带的相册实体。我认为那些不能被声明为Album实体的子类型,因为专辑不可能全部都是。它应该是Album实体的多值属性吗? 此外,每种类型的乙烯基,CD,磁带都有不同的属性(例如,乙烯基可能有颜色,CD可能有相关的视频剪辑等。)

对于艺术家实体,我怎样才能创作一个独唱艺术家和一个团体艺术家?在那一刻,我有一个Artist实体,其中包含Solo(具有更多属性)和Group(具有艺术家的多值属性)的子类型。

我在Solo和Group(MemberOf)之间建立了一个关系,这是一个Solo to Many Groups。

这是正确的还是应该让它与众不同?

由于

1 个答案:

答案 0 :(得分:1)

我可能会从这样的事情开始,然后根据其他需求进行调整:

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 | ... |
| .. | ........ | ......... | ... |
+----+----------+-----------+-----+