Relational Algebra and Relational Calculus Notes for GATE and UGC NET
Relational Algebra and Relational Calculus Notes
Detailed study material for GATE and UGC NET Computer Science aspirants.
Introduction to Relational Algebra
Relational Algebra is a procedural query language used to query databases in the relational model. It forms the theoretical foundation for most relational databases and SQL. Operations in relational algebra accept relations as input and produce relations as output, allowing complex queries to be constructed.
Key Operations in Relational Algebra
- Selection (σ): Retrieves rows from a relation that satisfy a specific condition.
- Projection (π): Retrieves specific columns (attributes) from a relation, eliminating duplicates by default.
- Union (∪): Combines tuples from two relations, removing duplicates. The relations must be union-compatible.
- Intersection (∩): Returns tuples common to both relations.
- Set Difference (-): Returns tuples present in one relation but not in the other.
- Cartesian Product (×): Combines every tuple from one relation with every tuple from another relation.
- Natural Join (⨝): Combines relations based on common attributes.
- Division (÷): Returns tuples in one relation that are associated with all tuples in another relation.
Examples
Selection Example
Query: Retrieve employees working in the HR department.
σ(Department='HR')(Employee)
Projection Example
Query: Retrieve the names and salaries of employees.
π(Name, Salary)(Employee)
Union Example
Query: Get a list of all faculty members (full-time and visiting).
Faculty ∪ VisitingFaculty
Introduction to Relational Calculus
Relational Calculus is a non-procedural query language. It specifies what to retrieve rather than how to retrieve it. Relational Calculus exists in two forms:
- Tuple Relational Calculus (TRC): Focuses on tuples.
- Domain Relational Calculus (DRC): Focuses on domains of attributes.
GATE and UGC NET Focus
Relational Algebra is emphasized in GATE Computer Science exams, with questions ranging from basic operations to complex query formulations. Relational Calculus questions, though less common, are occasionally included.
Sample GATE Question
Question: Write a relational algebra query to find students scoring more than 75 marks.
σ(marks > 75)(Student)