【问题标题】:How do I represent an entity being composed of 3 other entities?我如何表示一个由 3 个其他实体组成的实体?
【发布时间】:2021-06-10 01:45:16
【问题描述】:

我想在我的 ER 图中表示一个包由三 (3) 个不同的游戏组成。

My current ER model

如上图所示,礼包和游戏都是具有各自属性的产品。

这是他们各自的表格:

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)

我似乎找不到任何关于如何在模型中显示我的意思的示例,所以如果有人知道,我将不胜感激。

【问题讨论】:

  • 究竟是三 (3) 个不同的游戏?这个数字会因包装而异吗?
  • 是的,是的,三个不同的游戏,总是

标签: sql entity-relationship


【解决方案1】:

您可以使用 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)
)

【讨论】:

  • 我在询问模型表示,就像我附加的图像一样
猜你喜欢
  • 2017-04-21
  • 1970-01-01
  • 2014-12-22
  • 2021-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-08
相关资源
最近更新 更多