Recursive Relationships in ER diagrams (original) (raw)

Last Updated : 3 Apr, 2026

A relationship between two entities of the same entity set is called a recursive relationship or repeated relationship. Here, the same entity set participates more than once in a relationship type with a different role for each instance.

2

Recursive Relationship

**Example: In an organizational chart, an employee can have a relationship with other employees who are also in a managerial position. Similarly, in a social network, a user can have a relationship with other users who are their friends.

Cardinality in Recursive Relationship

We use cardinality constraints to specify the number of instances of the entity that can participate in the relationship. For example, in an organizational chart, an employee can have many subordinates, but each subordinate can only have one manager. This is represented as a one-to-many (1:N) relationship between the employee entity and itself. Let us suppose that we have an employee table, where:

1

Employee table Recursive Relationship

Here REPORTS_TO is a recursive relationship on the Employee entity type where each Employee plays two roles: Supervisor & Subordinate. Here, "Supervisor" and "Subordinate" are referred to as role names. The degree of the REPORTS_TO relationship is 1 (i.e., a unary relationship)

For the Subordinate role:

**Note: In this case, neither of the participants has total participation since the minimum cardinality for both roles is 0. Therefore, the relationship is represented with a single line (not a double line) in the ER diagram

Implementing a Recursive Relationship

To implement a recursive relationship, a foreign key of the employee’s manager number would be held in each employee record. A sample table would look something like this:-

Emp_entity( Emp_no,Emp_Fname, Emp_Lname, Emp_DOB, Emp_NI_Number, Manager_no);

Manager no - (this is the employee no of the employee's manager)

Example:

CREATE TABLE employee (
id INT PRIMARY KEY,
name VARCHAR(50),
manager_id INT,
FOREIGN KEY (manager_id) REFERENCES employee(id)
);

Here, the employee table has a foreign key column called manager_id that references the id column of the same employee table. This allows you to create a recursive relationship where an employee can have a manager who is also an employee.

Sample Employee Table Structure:

Emp_no Emp_Fname Emp_Lname Emp_DOB Emp_NI_Number Manager_no
1 John Doe 1980-01-01 123456789 NULL
2 Jane Smith 1990-05-15 987654321 1
3 Bob Johnson 1985-03-22 112233445 1

**In this table: