ER 设计中的弱实体
我有一个弱实体,它有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 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.
弱实体是一种具有主键的实体,该主键至少包含一个外键,但不仅仅包含外键。仅使用一种属性这是不可能的。因此,
id
,那么您就没有弱实体,而是强实体;id
、whatever
,并且id
本身已经是唯一的,那么id
本身应该成为你的主钥匙;id
、whatever
,并且id
和whatever
本身都不是唯一的,但是 < code>id,whatever
在一起是唯一的,那么它们是合法的主键,并且id
、whatever
一起作为外键,那么你就没有弱实体,而是子实体(外键是IS-A关系);id
和whatever
都是外键,则您没有弱实体,而是关系;id
和whatever
之一是外键,而另一个不是,则您的实体是弱实体。所有这些情况都可能发生。这取决于您想要建模的内容以及您拥有哪些相关信息。
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
id
, you do not have a weak entity, but a strong entity;id
,whatever
, andid
is already unique by itself, thenid
by itself should be your primary key;id
,whatever
, and neitherid
norwhatever
are not unique by themselves, butid
,whatever
together are unique, then they are a legitimate primary key, andid
,whatever
are a foreign key together, you do not have a weak entity, but a subentity (the foreign key is an IS-A relationship);id
andwhatever
are both foreign keys, you do not have a weak entity, but a relationship;id
andwhatever
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.