Prerequisite – ER Model
A relationship between two entities of similar entity type is called a recursive relationship. Here the same entity type participates more than once in a relationship type with a different role for each instance. In other words, a relationship has always been between occurrences in two different entities. However, it is possible for the same entity to participate in the relationship. This is termed a recursive relationship.
Let us suppose that we have an employee table. A manager supervises a subordinate. Every employee can have a supervisor except the CEO and there can be at most one boss for each employee. One employee may be the boss of more than one employee. Let’s suppose that REPORTS_TO is a recursive relationship on the Employee entity type where each Employee plays two roles
Supervisor and Subordinate are called “Role Names”. Here the degree of the REPORTS_TO relationship is 1 i.e. a unary relationship.
- The minimum cardinality of Supervisor entity is ZERO since the lowest level employee may not be a manager for anyone.
- The maximum cardinality of Supervisor entity is N since an employee can manage many employees.
- Similarly the Subordinate entity has a minimum cardinality of ZERO to account for the case where CEO can never be a subordinate.
- It maximum cardinality is ONE since a subordinate employee can have at most one supervisor.
Note – Here none of the participants have a total participation since both minimum cardinalities are Zero. Hence, the relationships are connected by a single line instead of a double line in the ER diagram.
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)
This article is contributed by Siddhant Bajaj 2. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Attributes to Relationships in ER Model
- Structural Constraints of Relationships in ER Model
- Relationships in ER model
- Data Objects, Attributes and Relationships in DBMS
- Total Recursive Functions and Partial Recursive Functions in Automata
- Difference between Recursive Predictive Descent Parser and Non-Recursive Predictive Descent Parser
- Minimization of ER Diagrams
- Discrete Mathematics | Hasse Diagrams
- Weak Entity Set in ER diagrams
- MySQL | Recursive CTE (Common Table Expressions)
- Recursive Descent Parser
- Algorithm for non recursive Predictive Parsing
- The Multistage Algorithm in Data Analytics
- Frequent Itemsets and it's applications in data analytics
Improved By : magbene