有 OR 条件的 ERD

ERD with OR condition

我正在尝试设计实体关系图(ERD、EER、ER)来描述数据架构,其中条件 1-1 是两个 0-1 关系的结果,它们之间具有 OR 逻辑。

在 schema below 中,我试图表明每个 Brand 有 1 个且只有 1 个 OrganizationBrand Group。换句话说,Brand 将始终需要链接到 OrganizationBrand Group。在 ERD 中定义它的正确方法是什么?

经典 ERD 不可能

  • Chen's notation one could be tempted to use a ternary relation, with a total participation of Brand and a partial participation of the others. But this would be wrong, since the ternary relation is about three entities participation (see explanation )中,并且没有办法表达关系之间的条件。
  • Everest's notation(更广为人知的名称是“鱼尾纹”)中,关系最多是二元关系,并且符号中的任何内容都不允许添加约束。

使用扩展 ERD 的解决方案

EERD 支持泛化(即使用“is-a”关系的继承):

  • 添加一个概念实体Brand Owner(或者你想怎么称呼它)
  • 添加 IsAOrganizationBrand groupBrand Owner
  • 的关系
  • BrandOrganizationBrand group两个关系替换为BrandBrand Owner
  • 的一对多关系

IsA 扩展在扩展 Chen 表示法中用三角形表示。不幸的是,鱼尾纹表示法中没有普遍认可的表示法(有些使用在专业化一侧带有条形的圆圈,有些使用一种逻辑门,并且不保证工具支持)。

为什么不使用 UML?

使用 UML,您的表将是 类,您必须用多重性替换乌鸦脚(它很简单,因为它在同一侧)。

最简单的方法是在两个备选 Brand 关联(ER 关系的 UML 术语)之间添加一个 {xor} 约束。如果愿意,您还可以使用自然语言约束,例如 {must be one of the two}

但是如果你喜欢泛化的想法,UML 提供了开箱即用的功能,«abstract» 类 的符号甚至可以澄清 Brand Owner 并不真正存在并且只是一个虚拟中介。