我想在ER图中表示一个包由三(3(个不同的游戏组成。
我目前的ER型号
正如您在上图中看到的,包和游戏都是具有各自属性的产品。
这是他们各自的表格:
packs(id, game1_id, game2_id, game3_id) where id is the primary key (also a foreign key of products)
games(id, studio_id) where id is the primary key (also a foreign key of products)
我似乎找不到任何关于如何在模型中展示我的意思的例子,所以如果有人知道我会很感激
您可以使用CHECK约束来确保所有3个游戏都不同。
create table packs(
id int not null primary key,
game1_id int not null,
game2_id int not null,
game3_id int not null,
constraint c12 check (game1_id <> game2_id),
constraint c23 check (game2_id <> game3_id),
constraint c31 check (game3_id <> game1_id),
-- FKs
constraint fk1 foreign key (game1_id) references games(id),
constraint fk2 foreign key (game2_id) references games(id),
constraint fk3 foreign key (game3_id) references games(id)
)