ER 设计中的弱实体

发布于 2024-12-10 02:46:52 字数 178 浏览 1 评论 0原文

我有一个弱实体,它有一个 id 作为其主键,并且还有另一个属性 (author_id),它必须引用另一个实体的 (Author)代码>'s) 主键。

所以我的问题是:弱实体可以有复合键(id,author_id)吗?

I have a weak entity and it has an id as its primary key and also has another attribute (author_id) which has to refer to another entity's (Author's) primary key.

So my question is this: can a weak entity have a composite key (id, author_id)?

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

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

发布评论

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

评论(2

隐诗 2024-12-17 02:46:52

如果 Id 是键,那么 (Id, Authorid) 不可能是同一个表中的键。没有一个键是另一个键的子集,因为根据定义,键应该是不可约唯一的。

你的问题的答案是肯定的。弱实体可能具有复合密钥。

If Id is a key then (Id, Authorid) can't possibly be a key in the same table. No key is ever a subset of another because keys by definition should be irreducibly unique.

The answer to your question is yes. A weak entity may have a composite key.

可可 2024-12-17 02:46:52

弱实体是一种具有主键的实体,该主键至少包含一个外键,但不仅仅包含外键。仅使用一种属性这是不可能的。因此,

  • 如果您的主键实际上只是id,那么您就没有弱实体,而是强实体;
  • 如果您的主键是 idwhatever,并且 id 本身已经是唯一的,那么 id 本身应该成为你的主钥匙;
  • 如果您的主键是 idwhatever,并且 idwhatever 本身都不是唯一的,但是 < code>id, whatever 在一起是唯一的,那么它们是合法的主键,并且
    • 如果idwhatever一起作为外键,那么你就没有弱实体,而是子实体(外键是IS-A关系);
    • 如果 idwhatever 都是外键,则您没有弱实体,而是关系;
    • 如果 idwhatever 之一是外键,而另一个不是,则您的实体是弱实体。

所有这些情况都可能发生。这取决于您想要建模的内容以及您拥有哪些相关信息。

A weak entity is an entity with a primary key that contains at least one of its foreign keys, but that doesn't contain only foreign keys. This is not possible with only one attribute. So

  • if your primary key is really just id, you do not have a weak entity, but a strong entity;
  • if your primary key is id, whatever, and id is already unique by itself, then id by itself should be your primary key;
  • if your primary key is id, whatever, and neither id nor whatever are not unique by themselves, but id, whatever together are unique, then they are a legitimate primary key, and
    • if id, whatever are a foreign key together, you do not have a weak entity, but a subentity (the foreign key is an IS-A relationship);
    • if id and whatever are both foreign keys, you do not have a weak entity, but a relationship;
    • if one of id and whatever is a foreign key and the other is not, you have a weak entity.

All of these cases may occur. It depends on what you want to model and which information you have about it.

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