我正在制作一个我在SQLite上参加过的音乐会的数据库。我设置了以下表格:1.场地1.艺术家1.音乐会如何使concert表可以有多个与之关联的艺术家ID?ArtistId1、ArtistId2、ArtistId3等是否应该只有多个列?或者,我需要第三个表来列出每个ArtistId和相应的ConcertId吗?我试过寻找方法,把多个艺术家ID的在同一列分隔不知何故,但不确定这是一个选项。
ykejflvf1#
当你有一个多对多关系(一个音乐会可以有很多艺术家,一个艺术家可以在很多音乐会上表演),你需要一个associative entity,它至少有两个表的外键:
create table concert_artists ( concert_id int not null references concerts, artist_id int not null references artists )
字符串这样的表也可以存储关于关系的信息,例如,您可以添加表演的表演编号(第一幕为1,依此类推)以及艺术家表演的分钟数:
create table concert_artists ( concert_id int not null references concerts, artist_id int not null references artists, performance_number int, performance_duration_minutes int )
型旁注:最好用单数命名表名,例如venue、artist和concert(而不是您命名的复数)。
venue
artist
concert
1条答案
按热度按时间ykejflvf1#
当你有一个多对多关系(一个音乐会可以有很多艺术家,一个艺术家可以在很多音乐会上表演),你需要一个associative entity,它至少有两个表的外键:
字符串
这样的表也可以存储关于关系的信息,例如,您可以添加表演的表演编号(第一幕为1,依此类推)以及艺术家表演的分钟数:
型
旁注:最好用单数命名表名,例如
venue
、artist
和concert
(而不是您命名的复数)。