ERD中的弱实体

发布于 2025-02-12 04:45:40 字数 154 浏览 0 评论 0 原文

在ERD中,当外键是主要键的一部分时,一个实体是一个弱实体。更具体地说,当实体具有存在依赖性和识别依赖性时,它是一个弱实体。

因此,如果我要制作一个人造键,它说实体是弱实体的新(单个)主要键,那么外键将不再是主要键,也消除了识别依赖性?因此,该实体不再是弱实体?即使关系没有改变?

In an ERD an entity is a weak entity when a foreign key is part of a primary key. More specifically when an entity has existence dependency and identification dependency, it is a weak entity.

So, if I was to make an artificial key that was say entity_id to be the new (single) primary key for a weak entity, the foreign key would no longer be a primary key, eliminating identification dependence as well? So the entity is no longer a weak entity? Even though the relationships were not changed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一百个冬季 2025-02-19 04:45:40

确实,弱实体的定义与其身份有关。 ERD的发明者Peter Chen已将其定义如下:

如果关系关系用于识别实体,我们称其为弱实体关系

换句话说,如果一个实体的所有属性足以唯一地识别它,那就是一个常规实体,但是如果需要另一个相关实体的属性(例如另一个实体的主要密钥),则很弱。

如果您通过生成弱实体自己自己的身份>(人工钥匙)它不再需要其他实体才能进行唯一的识别。因此,从定义上讲,这将是常规实体。顺便说一句,弱关系也必须更改为常规关系。

一个示例,

让我们以采购订单采购订单行的典型示例:可能存在几行,并且可能存在相同的材料,并且采购订单ID将被要求区分它们。主要密钥通常是复合的(采购订单 +行号)。因此,采购订单行绝对是一个弱实体。

如果用替代密钥替换主键,则该订单行的身份由新主键(独立于采购订单和行号)确保。从关系的角度来看,这是一种有效的方法和一种不同的现实。您突然无法想象没有命令的线路(即使从业务角度看不到很多)。

这不会改变约束或业务规则。通常,您将保持与订单的完全(强制性)关系。但是可以想象,重新分配采购订单,按顺序移动线,自然地自然地更改其他属性,例如订购的材料或所需数量。

Indeed, the definition of a weak entity is related to its identity. Peter Chen, the inventor of ERD has defined it as follows:

If relationship relations are used for identifying entities, we call it a weak entity relation

In other words, if all the own attributes of an entity are sufficient to uniquely identify it, it's a regular entity, but if an attribute of another related entity is needed (e.g. a primary key of another entity), it's weak.

If you give a weak entity its own identity by generating a surrogate key (artificial key) it would no longer need the other entity for the unique identification. So it would be by definition a regular entity. By the way, the weak relationship would also have to be changed to a regular one.

An example

Let's take the typical example of a Purchase Order and a Purchase Order Line : several lines with the same line-number and the same material could exist, and the purchase order id would be required to distinguish them. The primary key would typically be composite (purchase order + line number). So the Purchase Order Line is definitively a weak entity.

If you replace the primary key with a surrogate key, the identity of this order line is ensured by the new primary key, independently of the purchase order and the line number. From a relational perspective this is a valid approach and a different reality. You suddenly could imagine a line to exist without an order (even if it doesn't make much sense from a business perspective).

This would not change the constraints or the business rules. Typically, you'd maintain a total (mandatory) relationship to the order. But could imagine reassigning purchase orders, moving lines in the sequence, as flexibly and naturally as you would change other attributes such the material ordered or the desired quantity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文