Quick revision
The short answer
In an identifying relationship, the parent's key is part of the child's primary key, so the child cannot be identified, or exist, without its parent: order_line with primary key (order_id, line_no) is the classic example. In a non-identifying relationship, the child has its own key and merely references the parent through a foreign key, like orders(id, customer_id), so the parent is a fact about the child rather than part of its identity.
What to remember
In this answer, we saw that an identifying relationship puts the parent's key into the child's primary key, as order_line(order_id, line_no) does, so the child cannot exist without the parent and cascading deletes fit, while a non-identifying relationship gives the child its own key and a foreign key to the parent, as orders(id, customer_id) does. Surrogate keys often turn identifying relationships into non-identifying ones for ORMs, but the rule must survive as a unique constraint, and weak entities in ER notation are the entities on the child side of identifying relationships.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
In an identifying relationship, the parent's key is part of the child's primary key, so the child cannot be identified, or exist, without its parent: order_line with primary key (order_id, line_no) is the classic example. In a non-identifying relationship, the child has its own key and merely references the parent through a foreign key, like orders(id, customer_id), so the parent is a fact about the child rather than part of its identity.
Why this question is asked
ER diagrams are how teams agree on a data model before writing tables, and the distinction between identifying and non-identifying relationships decides primary keys, cascade rules and how an ORM maps the tables. Interviewers ask it to see whether we connect the notation to concrete DDL and to the trade-off that surrogate keys bring. In this answer, we will recap what identity means for a row, look at an identifying relationship with order lines, a non-identifying one with orders and customers, see how surrogate keys change the picture, and connect it to weak entities in ER notation.
1A Quick Recap of Identity in a Table
Every row needs something that identifies it uniquely: its primary key. The question behind identifying versus non-identifying is simply this: to identify a child row, do we need to know its parent?
For an order line, the answer is yes. Line 2 means nothing on its own; it is line 2 of order 1001. For an order, the answer is no. Order 1001 is order 1001 whoever placed it, and the customer is just one of its attributes. That difference becomes the shape of the primary key.
2An Identifying Relationship: Order Lines
In an identifying relationship the parent's key is part of the child's primary key.
Notice that line_no only has to be unique within its order, so every order can have a line 1. Because order_id is part of the key, it is necessarily NOT NULL: an order line cannot exist without an order. That is why ON DELETE CASCADE makes sense here. If an order is deleted, its lines have lost their identity and must go too. In practice, many businesses never delete orders, but the cascade expresses the dependency correctly.
3A Non-Identifying Relationship: Orders and Customers
The orders table above shows the other kind. orders has its own primary key, id, and refers to its customer through customer_id. The customer is not part of the order's identity. If we transferred an order to another customer account after a merge, the order would still be the same order, only its customer_id would change.
Non-identifying relationships can be mandatory, with customer_id NOT NULL as here, or optional, where the column allows NULL, for example an order placed as a guest. Cascading a delete from customer to orders is usually wrong for them, since orders have their own life, often legal retention requirements, and RESTRICT or a soft delete is the safer default.
| Aspect | Identifying | Non-identifying |
|---|---|---|
| Example | orders -> order_line | customer -> orders |
| Child primary key | (order_id, line_no), includes parent | id, its own |
| Foreign key column | always NOT NULL, part of the key | NOT NULL or nullable |
| Child without parent | impossible | possible if optional |
| Typical delete rule | ON DELETE CASCADE | RESTRICT or soft delete |
| ER notation | solid line, weak entity | dashed line |
4How Surrogate Keys Change the Picture
Many teams give every table a single generated id, a surrogate key, including order_line. Then order_line has id as its primary key and order_id becomes an ordinary foreign key, so in the diagram the relationship turns non-identifying. ORMs like JPA and Hibernate prefer this, because a single-column id is simpler to map than a composite key, which needs an @IdClass or @EmbeddedId.
But there is a catch: the business rule did not go away. Each order still has at most one line 2, and the line still cannot exist without its order. So we keep order_id NOT NULL, keep the cascade, and keep the rule as a UNIQUE constraint on (order_id, line_no). Without that constraint, a retry bug could insert line 2 twice and nothing would stop it. The relationship is non-identifying in the schema but still dependent in the business, and a good model makes that visible.
5Weak Entities in ER Notation
In classic ER modelling, an entity that cannot be identified by its own attributes alone is called a weak entity. It has a partial key, here line_no, that is only unique together with the key of its owner entity, here the order. Chen notation draws a weak entity with a double rectangle and its identifying relationship with a double diamond. In crow's foot notation, the identifying relationship is a solid line.
So weak entities and identifying relationships are two views of the same idea: the owner's key completes the weak entity's identity. Other common examples are a hotel room within a building, (building_id, room_no), or an installment within a loan, (loan_id, installment_no).
6Follow-up questions
When would you keep a composite primary key instead of adding a surrogate key?
For pure join tables, such as book_author(book_id, author_id), the composite key is the natural identity, nothing else references the row, and a surrogate id would only add an index. For child tables that other tables reference, a surrogate key keeps those foreign keys to one column, and the natural composite stays as a unique constraint.
Does an identifying relationship always mean ON DELETE CASCADE?
It means the child cannot exist without the parent, so if the parent row is deleted the child must be deleted too, or the delete must be refused. Cascade is the natural choice, but for financial records we may prefer RESTRICT and never physically delete parents at all.
Can a relationship be identifying and optional?
No. If the parent's key is part of the child's primary key, it cannot be NULL, so every child has a parent. Optional relationships are always non-identifying.
7Conclusion
In this answer, we saw that an identifying relationship puts the parent's key into the child's primary key, as order_line(order_id, line_no) does, so the child cannot exist without the parent and cascading deletes fit, while a non-identifying relationship gives the child its own key and a foreign key to the parent, as orders(id, customer_id) does. Surrogate keys often turn identifying relationships into non-identifying ones for ORMs, but the rule must survive as a unique constraint, and weak entities in ER notation are the entities on the child side of identifying relationships.
Open with
The difference is whether the parent is part of the child's identity. In an identifying relationship, the child's primary key includes the parent's key. The standard example is order lines: the primary key is order_id plus line_no, because line 2 only means something as line 2 of a particular order.
Then, if they want more
That makes order_id necessarily not null, the child cannot exist without the parent, and ON DELETE CASCADE usually makes sense. In ER terms, the order line is a weak entity: line_no is only a partial key, completed by the owner's key. In a non-identifying relationship, the child has its own key and simply references the parent.
Orders with their own id and a customer_id column are the example: the customer is an attribute of the order, could even change after an account merge, and the foreign key can be mandatory or optional. Cascading deletes are usually wrong there.
In practice, many teams give every table a surrogate id, which turns order lines into a non-identifying relationship in the schema and makes JPA mapping simpler than a composite key.
When I do that, I keep the business rule with a unique constraint on order_id and line_no, keep order_id not null and keep the cascade, so the dependency is still enforced.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is the difference between an identifying and a non-identifying relationship in an...": https://scrivio-interview-library.netlify.app/databases/data-modeling/6b345be707/