识别关系和非识别关系有什么区别? [英] What's the difference between identifying and non-identifying relationships?

查看:34
本文介绍了识别关系和非识别关系有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直无法完全理解这些差异.你能描述这两个概念并使用现实世界的例子吗?

I haven't been able to fully grasp the differences. Can you describe both concepts and use real world examples?

推荐答案

  • 识别关系是指子表中某行的存在依赖于父表中的某行.这可能会令人困惑,因为如今为子表创建伪键是很常见的做法,但不是将外键设为子表主键的父部分.正式地,执行此操作的正确"方法是将外键作为子键的主键的一部分.但逻辑关系是,没有父母,孩子就不能存在.

    • An identifying relationship is when the existence of a row in a child table depends on a row in a parent table. This may be confusing because it's common practice these days to create a pseudokey for a child table, but not make the foreign key to the parent part of the child's primary key. Formally, the "right" way to do this is to make the foreign key part of the child's primary key. But the logical relationship is that the child cannot exist without the parent.

      示例:Person 有一个或多个电话号码.如果他们只有一个电话号码,我们可以简单地将其存储在 Person 列中.由于我们想要支持多个电话号码,我们创建了第二个表 PhoneNumbers,其主键包括引用 Person 表的 person_id.

      Example: A Person has one or more phone numbers. If they had just one phone number, we could simply store it in a column of Person. Since we want to support multiple phone numbers, we make a second table PhoneNumbers, whose primary key includes the person_id referencing the Person table.

      我们可能认为电话号码属于一个人,即使它们被建模为单独表的属性.这是一个强有力的线索,表明这是一个识别关系(即使我们没有在 PhoneNumbers 的主键中逐字地包含 person_id).

      We may think of the phone number(s) as belonging to a person, even though they are modeled as attributes of a separate table. This is a strong clue that this is an identifying relationship (even if we don't literally include person_id in the primary key of PhoneNumbers).

      非识别关系是指父项的主键属性不得成为子项的主键属性.一个很好的例子是查找表,例如 Person.state 上的外键引用 States.state 的主键.Person 是相对于 States 的子表.但是 Person 中的一行不是由它的 state 属性标识的.IE.state 不是 Person 的主键的一部分.

      A non-identifying relationship is when the primary key attributes of the parent must not become primary key attributes of the child. A good example of this is a lookup table, such as a foreign key on Person.state referencing the primary key of States.state. Person is a child table with respect to States. But a row in Person is not identified by its state attribute. I.e. state is not part of the primary key of Person.

      非识别关系可以是可选强制,这意味着外键列分别允许NULL或不允许NULL.

      A non-identifying relationship can be optional or mandatory, which means the foreign key column allows NULL or disallows NULL, respectively.

      另见我对仍然对识别感到困惑的回答与非识别关系

      这篇关于识别关系和非识别关系有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆