I haven\'t been able to fully grasp the differences. Can you describe both concepts and use real world examples?
user287724's answer gives the following example of the book and author relationship:
A book however is written by an author, and the author could have written multiple books. But the book needs to be written by an author it cannot exist without an author. Therefore the relationship between the book and the author is an identifying relationship.
This is a very confusing example and is definitely not a valid example for an identifying relationship
.
Yes, a book
can not be written without at least one author
, but the author
(it's foreign key) of the book
is NOT IDENTIFYING the book
in the books
table!
You can remove the author
(FK) from the book
row and still can identify the book row by some other field (ISBN
, ID
, ...etc) , BUT NOT the author of the book!!
I think a valid example of an identifying relationship
would be the relationship between (products table) and a (specific product details table) 1:1
products table
+------+---------------+-------+--------+
|id(PK)|Name |type |amount |
+------+---------------+-------+--------+
|0 |hp-laser-510 |printer|1000 |
+------+---------------+-------+--------+
|1 |viewsonic-10 |screen |900 |
+------+---------------+-------+--------+
|2 |canon-laser-100|printer|200 |
+------+---------------+-------+--------+
printers_details table
+--------------+------------+---------+---------+------+
|Product_ID(FK)|manufacturer|cartridge|color |papers|
+--------------+------------+---------+---------+------+
|0 |hp |CE210 |BLACK |300 |
+--------------+------------+---------+---------+------+
|2 |canon |MKJ5 |COLOR |900 |
+--------------+------------+---------+---------+------+
* please note this is not real data
In this example the Product_ID
in the printers_details
table is considered a FK references the products.id
table and ALSO a PK in the printers_details
table , this is an identifying relationship because the Product_ID
(FK) in the printers table IS IDENTIFYING the row inside the child table, we can't remove the product_id
from the child table because we can't identify the row any more because we lost it's primary key
If you want to put it in 2 lines:
an identifying relationship is the relationship when the FK in the child table is considered a PK(or identifier) in the child table while still references the parent table
Another example may be when you have 3 tables (imports - products - countries) in an imports and exports for some country database
The import
table is the child that has these fields(the product_id
(FK), the country_id
(FK) , the amount of the imports , the price , the units imported , the way of transport(air, sea) )
we may use the (
product_id, the
country_id`) to identify each row of the imports "if they all in the same year" here the both columns can compose together a primary key in the child table(imports) and also referencing there parent tables.
Please I'm happy I finally understand the concept of the identifying relationship
and non identifying relationship
, so please don't tell me I'm wrong with all of these vote ups for a completely invalid example
Yes logically a book can't be written without an author but a book can be identified without the author,In fact it can't be identified with the author!
You can 100% remove the author from the book row and still can identify the book!.
An Identifying relationship specifies that a child object cannot exist without the parent object
Non-identifying relationships specifies a regular association between objects, 1:1 or 1:n cardinality.
Non-identifying relationships can be specified as optional where a parent is not required or mandatory where a parent is required by setting the parent table cardinality...
Non-identifying relationship
A non-identifying relationship means that a child is related to parent but it can be identified by its own.
PERSON ACCOUNT
====== =======
pk(id) pk(id)
name fk(person_id)
balance
The relationship between ACCOUNT and PERSON is non-identifying.
Identifying relationship
An identifying relationship means that the parent is needed to give identity to child. The child solely exists because of parent.
This means that foreign key is a primary key too.
ITEM LANGUAGE ITEM_LANG
==== ======== =========
pk(id) pk(id) pk(fk(item_id))
name name pk(fk(lang_id))
name
The relationship between ITEM_LANG and ITEM is identifying. And between ITEM_LANG and LANGUAGE too.
Bill's answer is correct, but it is shocking to see that among all the other answers no one points out the most significant aspect.
It has been said over and over again, that in an identifying relationship the child can not exist without the parent. (e.g. user287724). This is true, but completely misses the point. It would be enough for the foreign key to be non-null to achieve this. It does not need to be part of the primary key.
So here is the real reason:
The purpose of an identifying relationship is that the foreign key can NEVER CHANGE, because it is part of the primary key... therefore identifying!!!
Let's say we have those tables:
user
--------
id
name
comments
------------
comment_id
user_id
text
relationship between those two tables will identifiying relationship. Because, comments only can be belong to its owner, not other users. for example. Each user has own comment, and when user is deleted, this user's comments also should be deleted.
An identifying relationship is between two strong entities. A non-identifying relationship may not always be a relationship between a strong entity and a weak entity. There may exist a situation where a child itself has a primary key but existence of its entity may depend on its parent entity.
For example : a relationship between a seller and a book where a book is being sold by a seller may exist where seller may have its own primary key but its entity is created only when a book is being sold
Reference based on Bill Karwin