识别与不识别的关系(再次!!!) [英] Identifying vs Non-Identifying Relationships (Again!!!)

查看:221
本文介绍了识别与不识别的关系(再次!!!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在stackoverflow上看了很多答案,但我仍然对这个概念感到困惑。具体来说,我已经介绍了这篇文章(包括它引用的所有内容),但似乎并没有把握这个概念(或者是我的基数(n:m等)和身份之间的混淆):

So, I've read a whole lot of answers here on stackoverflow, but I'm still confused about the whole concept thereof. Specifically, I've gone over this article (including all the ones it references), but can't seem to find a solid grasp on the concept (or perhaps it is my confusion between cardinality (n:m, etc.) and identities):

仍然困惑关于识别与不确定的关系

我的问题是这样的:我知道识别关系意​​味着子实体的主键必须包括其外键,而与非识别关系相反(这是正确的)吗?现在,这似乎有点向前思考给我?其中一个意见之一也是这样说的。我如何退后退,实际看到哪个关系是哪个身份?

My issue is this: I know that identifying relationships imply that the primary key of a child entity must include its foreign key, and that the opposite is true for non-identifying relationships (Is this correct?). Now, this seems a bit too "forward thinking" to me? The same was also said in one of the comments in one of the links. How can I "take a step back" and actually see which relations are of which identity?

例如,我有两个困境:


  1. job_title (parent,1)to employee (child,1 .. *)。我正确的想法是因为job_title是一个查找表,它必须是一个非识别关系?或者说如果没有job_title,员工就不能存在,所以一定要确定呢?还是定义这种情况的关系?

  2. 员工 employee_equipment (m:n基数之间的桥接实体)到设备。现在,我看到这必须是employee_equipment两侧的识别关系。但是,如果员工不需要设备呢?可以有一个可选的识别关系吗?

  1. job_title (parent, 1) to employee (child, 1..*). Am I right in thinking that, because job_title is a lookup table, it must be a non-identifying relation? Or would it be more accurate in saying that "an employee can't exist without a job_title, thus it must be identifying"? Or would it be the relationship defining that scenario?
  2. employee to employee_equipment (bridging entity between the m:n cardinality) to equipment. Now, I read that this has to be an identifying relationship on both sides of employee_equipment. But, what if an employee doesn't NEED equipment? Can one have an optional identifying relationship?

我想我真的在寻找一种方法来识别哪些身份表应属于,而不必考虑主/外键,或任何真正的技术

I guess that I'm really looking for a way to identify which identity tables should belong to, without thinking of primary/foreign keys, or anything really technical for that matter.

任何帮助将不胜感激!

推荐答案

- 思考可选性和身份之间的联系。直到整个事情更自然地对你来说,最好将它们认为是完全无关的

You are over-thinking the linkage between optionality and identity. Until the whole thing comes more naturally to you, it's best to think of them as being completely unrelated.

关于可选性,重要的是记住可选性是定向的。要使用您的 employee_equipment的示例:当然,员工不需要设备。从 employee employee_equipment 的一对多关系是可选的。同时从相反的角度来看,这种关系是强制性的。您不能在 employee_equipment 中创建一条记录,除非有一个员工将其与。

About optionality, it is important to remember that the optionality is directional. To use your example of employee_equipment: Sure, employees don't need equipment. The one-to-many relationship from employee to employee_equipment is optional. At the same time, looking at it from the opposite perspective, the relationship is mandatory. You can't have a record in employee_equipment unless there is an employee to associate it with.

身份与可选性无关,除了巧合,从孩子到父母必须具有识别关系。从父母到孩子也是强制性的,就身份而言,既不在这里也不存在。

Identity has nothing to do with optionality, except coincidentally an identifying relationship is mandatory from the child to the parent. Whether it is also mandatory from the parent to the child is neither here nor there as far as identity is concerned.

什么使得关系识别是你必须知道什么你正在谈论的父母(以及其他一些事情),以便知道你在说什么孩子。也就是说,小孩的主键必须包含父母的外键。

What makes a relationship identifying is that you have to know what parent you are talking about (as well as some other things) in order to know what child you are talking about. That is, the primary key of the child must include a foreign key to the parent.

纯交叉表(例如 employee_equipment )是很好的例子。纯交叉点的主键是外键与两个父表的组合。请注意,有些人还可以在这些表格中添加替代密钥。如果有多个候选键,从身份角度来说,这并不重要。确定身份的重要内容是外键是候选键的一部分,是否该候选键是否恰好是主键。

Pure intersection tables (e.g. employee_equipment) are good examples of this. The primary key of a pure intersection is the combination of the foreign keys to both parent tables. Note that some people may also add a surrogate key to these kinds of tables. It doesn't matter so much from an identity perspective if there are multiple candidate keys. What is important in determining identity is whether the foreign key is part of a candidate key, whether or not that candidate key happens to be the primary key.

另一个很好的例子像数据库的元数据目录,其中列由其所属的表标识,就像表所在的模式一样,等等。知道一个列称为 NAME 不会告诉您它是哪一列。知道这是 CUSTOMER 表中的 NAME 列有帮助。 (您还必须知道哪个模式 CUSTOMER 在,等等)。

Another good example would be something like a database's metadata catalog, where a column is identified by the table to which it belongs, just as the table is identified by the schema it is in, and so on. Knowing that a column is called NAME doesn't tell you which column it is. Knowing that it is the NAME column in the CUSTOMER table helps. (You'll also have to know which schema CUSTOMER is in, and so forth).

这篇关于识别与不识别的关系(再次!!!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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