通过 EntityName 表映射 M:N 关系中的变量实体类型
我经常看到 M:N 关系的“链接”表,其中 N 可以是 1..X 类型的实体/类,因此该表包含引用 ClassName 表的 classNameId 和引用特定实体表的 classPK。
这怎么称呼?在没有 EntityName 表的情况下是否有具有相同效果的替代方案?
I often see "linking" tables for M:N relationship, where N can be 1..X types of entities/classes, so that the table contains classNameId referring to ClassName table and classPK referring to the particular Entity table.
How is this called ? Does it have an alternative with the same effect without having the EntityName table ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ER 模型中,实体和子实体可以通过继承进行关联,就像对象模型中的类和子类一样。当您将 ER 模型转换为关系模型时,问题就会出现。关系模型本身不支持继承。
这种设计模式称为泛化-专业化或简称为gen-spec。不幸的是,许多数据库教程都跳过了如何针对特定情况设计表。
但这很好理解。它看起来与您的模型完全不同,但如果需要,您可以创建视图使其看起来像您的模型。请查找“泛化专业化关系建模”以获取有关如何执行此操作的说明。
主要技巧是专用表从通用表的 PK 中“继承”其主键的值。这里“继承”的意思是,它是相同值的副本。因此,每个专用表中的 PK 也是返回通用表中相应条目的 FK 链接。
In the ER model, entities and subentities can be related by inheritance, the same way classes and subclasses are in an object model. The problem comes up when you transform your ER model into a relational model. The relational model does not support inheritance as such.
The design pattern is called is called generalization-specialization or gen-spec for short. Unfortunately, many database tutorials skip over how to design tables for a gen-spec situation.
But it's well understood.It looks quite different from your model, but you could create views that make it look like your model if necessary. Look up "generalization specialization relational modeling" for explanations of how to do this.
The main trick is that the specialized tables "inherit" the value of their primary key from the PK of the generalized table. The meaning of "inherit" here is that it's a copy of the same value. Thus the PK in each specialized table is also an FK link back to the correpsonding entry in the generalized table.