Skip to content
C

Recursive Relationship


Recursive Relationship

Definition

A recursive relationship (also called a unary relationship, matching degree 1 from 6.12) is a relationship in which an entity set is related to itself — the same entity set participates on both "ends" of the relationship, often in two different roles.

Worked Example

The classic example is Manages, on the Employee entity set: one employee (in the role of "manager") manages other employees (in the role of "subordinate"). In an ER diagram, the two lines from the Employee rectangle to the Manages diamond are each labeled with a role name — "Manager" and "Subordinate" — to distinguish the two participations of the same entity set. A second example in the college database: a Prerequisite_Of relationship on Course, where one course is a prerequisite for another course (e.g., "Data Structures" is a prerequisite for "Algorithms").

Edge Cases

  • Because both roles come from the same entity set, role names are mandatory for clarity in a recursive relationship — without them, it would be ambiguous which line represents which role when reading the diagram.
  • A recursive relationship can have any cardinality, just like an ordinary binary relationship: Manages is typically 1:N (one manager, many subordinates, but each employee has at most one direct manager), whereas Prerequisite_Of can be M:N (a course can have multiple prerequisites, and be a prerequisite for multiple other courses).
  • When mapped to a relational table, a recursive 1:N relationship like Manages typically becomes a self-referencing foreign key in the same table — e.g., Employee(Employee_ID, Name, Manager_ID) where Manager_ID references Employee.Employee_ID.
  • Do not confuse a recursive relationship with a weak entity or identifying relationship — recursion is purely about degree (same entity set on both sides); it says nothing about whether either participant is weak.

Key Takeaways / Interview Q&A

Q: Why are role names necessary in a recursive relationship but usually optional in an ordinary binary relationship? A: Because in a recursive relationship both connection lines come from the SAME entity set, so without role labels ("Manager" vs. "Subordinate") there would be no way to tell the two participations apart.

Q: How does a 1:N recursive relationship like Manages typically get implemented in SQL? A: As a self-referencing foreign key column in the same table, e.g., a ManagerID column in the Employee table that references EmployeeID in that same table.

Q: Is a recursive relationship the same as a relationship having degree 1 (unary)? A: Yes — "recursive" and "unary" describe the exact same structural situation: an entity set related to itself.

Mock Test

  • Recursive Relationship - Quick Test

    8 questions on Recursive Relationship.

    8 questions · 8 min · Medium
    Start Mock Test