💾
Welcome to DataGenesis !
  • 🚀 Welcome to the Database Management System Playground! 📊💾
  • Basics of DBMS
    • Database Management System
    • DBMS V/S File System
    • DBMS Architectures
    • Tier 3 Architecture / Three Schema Architecture
  • E-R Data Model
    • Basics of E-R Model
    • Attributes in E-R Model
    • Null Values
    • Strong & Weak Entities
    • Relationship Constraints
    • Recursive Relationships
    • E-R Diagrams
    • Extended E-R Model
  • Relational Model
    • Relational Model
    • Facts About Relational Model
    • Types of Keys in Relational Model
    • Integrity Constraints
    • Anomalies in Relational Model
  • Transform - ER Model to Relational Model
    • Mapping from ER Model to Relational Model
  • SQL - Structured Query Language
    • SQL
    • CRUD Operations
    • Data Types
    • Type of Commands in SQL
    • Working With Commands
    • Data Retrieval Commands
  • Normalisation
    • Functional Dependencies
    • Armstrong's Axioms
    • Multivalued Dependency
    • 1 Normal Form
    • 2 Normal Form
    • 3 Normal Form
    • Boyce-Codd Normal Form (BCNF)
    • 4 Normal Form
    • 5 Normal Form
    • Lossless Decomposition, Lossless Join ,and Dependency Preserving Decomposition, Denormalization
  • Concurrency Control
    • Transactions & Concurrency
    • Scheduling of Transactions
    • Problems & Strategies in Concurrency Control
    • Transaction & ACID Properties
    • How to implement ACID Properties
    • Atomicity Techniques
    • Durability Techniques
    • Implementing Locking in DBMS
    • Concurrency Control Protocols
      • Two Phase Locking
      • Timestamp Ordering
      • Multi Version Concurrency Control Techniques
    • Starvation in DBMS
    • Deadlock in DBMS
    • Log Based Recovery
  • NoSQL & Types of Databases
    • SQL V/S NoSQL
    • Types of Databases
  • DB Optimization
    • File Organization
      • Hash File Organizations
      • B+ Tree File Organization: A Guide to Efficient Data Indexing
      • Cluster File Organization
    • Indexing in DBMS
      • Primary Indexing
      • Clustered Indexing
      • Secondary Indexing
      • Multilevel Indexing
  • Distributed Databases
    • Database Clustering
    • Partitioning and Sharding
    • CAP Theorm
Powered by GitBook
On this page

Was this helpful?

  1. E-R Data Model

Recursive Relationships

Recursive relationships, also known as self-referential or reflexive relationships, occur when entities within a database have a relationship with themselves. In other words, an entity or record within a table is related to another record within the same table. Recursive relationships are commonly used to represent hierarchical or tree-like structures within a database. Here are a few examples to help illustrate recursive relationships:

  1. Employee Hierarchy: In a database tracking employee information, you might have an "Employee" table. Each employee has an ID, name, and supervisor ID. The supervisor ID would be a foreign key referencing another employee's ID, indicating that one employee (the subordinate) reports to another (the supervisor). This creates a recursive relationship because employees can be supervisors of other employees.

Employee Table:
| ID | Name     | Supervisor_ID |
|----|----------|---------------|
| 1  | John     | NULL          |
| 2  | Alice    | 1             |
| 3  | Bob      | 1             |
| 4  | Carol    | 2             |

In this example, John is the supervisor of Alice and Bob, and Alice is the supervisor of Carol.

  1. Organizational Structure: In a database representing an organization's structure, you may have a "Department" table. Each department can have a reference to its parent department, creating a recursive relationship. This structure can represent a hierarchy of departments within an organization.

Department Table:
| ID | Name         | Parent_Department_ID |
|----|--------------|----------------------|
| 1  | HR           | NULL                 |
| 2  | Finance      | NULL                 |
| 3  | Payroll      | 2                    |
| 4  | Benefits     | 2                    |

In this example, the Finance department has two sub-departments: Payroll and Benefits.

  1. Comment Threads: In a system where users can leave comments on posts or other comments, you might have a "Comment" table. Each comment can have a parent comment (a reply to another comment) or be a top-level comment (a comment on a post). This creates a recursive relationship among comments.

Comment Table:
| ID | Text                | Parent_Comment_ID |
|----|---------------------|-------------------|
| 1  | First comment       | NULL              |
| 2  | Reply to comment 1  | 1                 |
| 3  | Reply to comment 2  | 2                 |

In this example, comment 1 is the parent of comment 2, and comment 2 is the parent of comment 3.

Recursive relationships are essential for modeling data where entities have hierarchical or tree-like structures. They allow you to represent parent-child relationships within a single table, making it possible to query and navigate these structures efficiently within a relational database.

PreviousRelationship ConstraintsNextE-R Diagrams

Last updated 1 year ago

Was this helpful?