I've recently started using MySQL Workbench to manage EER diagrams. Up until now I have been using phpmyadmin and I never came across the terms Identifying & Non-Identifying relationships.
I have looked up the difference online and read a few Stack Overflow answers on the topic, but I'm still pretty much clueless.
From what I understand, I am going to give an example of a scenario in my database and I will propose the right solution.
So in my database I have a users
table and a contact
table containing various methods to contact the user (such as email & phone number). Since a contact record cannot exist without relating to a user, this should be an identifying relationship.
Here is what my tables look like:
+-------+ +-------+
| users | |contact|
+-------+ +-------+
| id | |id |
+-------+ |userid |
|contact| // contains email or phone
|type | // specifies if email or phone
+-------+
However, when I create an identifying relationship between the two tables, it makes the userId
part of a composite key. I understand that the table can have a composite primary key made up of userid
and contact
, however want to keep a consistent structure throughout the database where every table has its own surrogate key. (I have seen many times that it's better practice to use surrogate keys over composite keys.)
So in this case, what's the actual correct way to do this? Should I use a composite key and scrap the surrogate key (which I really would prefer not to do)? Or should I use a non-identifying relationship in this case?
Please explain exactly what the difference between the two relationships is and why identifying relationships need to point to a field which is part of a composite key.