Identifying vs Non-Identifying Relationships (Again!!!)
Asked Answered
T

2

4

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):

Still Confused About Identifying vs. Non-Identifying Relationships

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?

For example, I have two dilemmas:

  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.

Any help would be much appreciated!

Tripartite answered 16/3, 2013 at 0:18 Comment(1)
Also, many of the articles give too 'concrete' examples, such as books and authors. How would these identities work with abstract things, such as job_title that I mentioned above?Tripartite
C
5

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.

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.

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.

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).

Catechol answered 16/3, 2013 at 0:40 Comment(1)
+1 That's the only explanation anywhere I've understood yet: "What makes a relationship identifying is that you have to know what parent you are talking about ... in order to know what child you are talking about." -thank youFounder
E
3

Joel has provided a good answer (+1 to him), let me just offer a small mental shortcut that you can use when thinking about identifying relationships... just ask yourself:

Can I achieve uniqueness only with the attributes of the child entity?

If no, and you need to include the attributes migrated from the parent into the child key to make it unique, then you have an identifying relationship1. It's about identification-dependence, not existence-dependence2!

You might be interested in this post for some more musings on the topic.


1 And the child entity is "weak" or "dependent".

2 Although identification-dependence usually implies existence-dependence.

Etem answered 16/3, 2013 at 11:35 Comment(4)
Ok, this makes a lot of sense. But now, I'm using the whole process of assigning a completely independent PK to each table (meaning, each table has a Table_ID value, regardless of what table it is). Am I correct in thinking that I should now rather not do that and try and figure out if I can make a record unique with values that it HAS, and if not, then it must have an identifying relation with its parent?Tripartite
@user1795229 - Whether to always have a surrogate key is a question that can become a religious war. Remember to keep separate in your head what you do for the physical database and what you do from a logical analysis perspective. If you add a meaningless sequence number to a pure intersection table and make it the physical primary key, it means you don't need the two FKs for your PK any more, but it does nothing to change the fact that the two FKs remain a candidate key and are still going to be identifying (logically) - even if there is no unique index on the two FKs defined physically.Catechol
@user1795229 - Also: be sure to read Branko's answer here and the one he linked to. They should help you to understand identifiers in weak entities better. (+1)Catechol
@user1795229 Please don't add a surrogate key blindly nor use it as an excuse to stop thinking about natural keys. If you have specific reasons for a surrogate key, by all means do it, just don't do it blindly. If there is a natural key intrinsic to your data, you need to enforce it in the database (via PRIMARY KEY or UNIQUE constraint), regardless of whether you also add a surrogate key.Etem

© 2022 - 2024 — McMap. All rights reserved.