一个实体并不弱,因为它不能独立存在,而是因为它无法独立识别.因此,“引导”到弱实体的关系称为“识别”关系.在实践中,这意味着父母的主键被迁移到子PK的子集(通常是

proper)中(术语“弱实体”通常与主键相关地定义,但理论上它可以应用于任何键).

拥有一个不能独立存在的实体是完全合法的,但可以独立识别 – 换句话说,就是与非NULL的非识别关系.

您必须要问:historyLineID可以单独使用,还是与orderID结合使用?我怀疑后者就是这种情况,这会使它成为一个弱势实体.

Is this really a correct weak entity relationship?

你告诉我们的不是一个弱实体 – 父母的PK不会迁移到孩子的PK中.

Is there other ways to identify them?

你基本上有两个选择:

> orderHistory有一个复合PK:{orderID,historyLineID},其中orderID是FK.顺便说一句,这个PK可以被认为是“自然的”:

> orderHistory有一个代理PK:{orderHistoryID},而orderID在PK之外.您仍然需要备用密钥{orderID,historyLineID}:

Should I add the PK of table order to table orderHistory and make it a composite primary key?

是的,这是上面描述的第一个选项.除非你在orderHistory本身有子关系,否则这也是最好的解决方案.如果orderHistory确实有孩子,那么这可能是也可能不是最佳解决方案,具体取决于几个因素.

What if I decide to model this as a normal One-To-Many relationship where orderID is added as a foreign key instead? what are the cons of doing so?

这不是 – 或者.字段可以是FK和(主要或备用)键的一部分,如上所示.

Will ignoring Weak entities at all cause any problems later in a design provided all tables are in 3rd normal form?

除非您正确指定密钥,否则您将无法达到3NF,如果不考虑哪个实体可以独立识别,哪个不能独立识别,您将无法做到这一点.

Logo

一站式 AI 云服务平台

更多推荐