In this article Relational Algebra Operations in DBMS we give the information about Relational Algebra is a procedural query language that takes relations as input and returns relations as output. It is the theoretical foundation of SQL queries.
Relational Algebra Operations:
Relational Algebra is a procedural query language that takes relations as input and returns relations as output. It is the theoretical foundation of SQL queries.
- Selection (σ)
- Purpose: Filters rows (tuples) based on a condition.
- Symbol: σ (sigma)
- Operation: σ_condition(Relation)
Example:
σ_Course = ‘BCA'(Student)
Returns all students enrolled in the BCA course.
- Projection (π)
- Purpose: Selects specific columns (attributes).
- Symbol: π (pi)
- Operation: π_attribute_list(Relation)
π_Name, Course(Student)
Returns only the Name and Course columns from Student.
- Set Operations
These require that the two relations have the same schema.
Operation | Symbol | Description |
Union | ∪ | Combines tuples from both relations |
Intersection | ∩ | Returns common tuples |
Difference | − | Returns tuples in one but not the other |
Example:
Student ∪ Alumni
Returns all unique rows that are in either Student or Alumni.
- Join Operations
Used to combine rows from two or more tables based on a common attribute.
Type | Symbol/Keyword | Description |
Cartesian Product | × | Combines every tuple of R1 with every tuple of R2 |
Theta Join | ⋈_condition | Join based on any condition |
Equi Join | ⋈_A=B | Join where attribute values are equal |
Natural Join | ⋈ | Automatically joins on same-named attributes |
Outer Join | LEFT/RIGHT/FULL | Includes unmatched rows |
Example:
Student ⋈_Student.RollNo = Enrollment.RollNo Enrollment
- Division (÷)
- Purpose: Finds tuples in one relation that are related to all tuples in another.
- Use Case: Queries like “Find students who enrolled in all courses.”
Example:
Finds students who are enrolled in every course.
Relational Calculus
Relational Calculus is a non-procedural query language; it specifies what to retrieve, not how.
There are two types:
- Tuple Relational Calculus (TRC)
- Syntax: { t | P(t) }
Where t is a tuple variable, and P(t) is a predicate (condition).
Example:
{ t | t ∈ Student AND t.Course = ‘BCA’ }
Returns all student tuples where the course is BCA.
- Domain Relational Calculus (DRC)
- Syntax: { <a1, a2, …, an> | P(a1, a2, …, an) }
Each variable represents a domain value (attribute).
Example:
{ <name> | ∃ rollNo, course (Student(rollNo, name, course) ∧ course = ‘BCA’) }
Returns names of students where the course is BCA.
Comparison Table: TRC vs DRC
Feature | Tuple Relational Calculus (TRC) | Domain Relational Calculus (DRC) |
Based on | Tuples (rows) | Domains (columns/attributes) |
Syntax | `{ t | P(t) }` |
Focus | Entire tuple | Individual attribute values |
More readable for | Simple conditions | Specific value-based queries |
Conclusion
Concept | Key Use |
Selection (σ) | Filter rows (WHERE in SQL) |
Projection (π) | Select columns (SELECT in SQL) |
Set Ops | Union, Intersection, Difference |
Join | Combine related tables (JOIN in SQL) |
Division | Match tuples related to all values in another set |
TRC & DRC | Theoretical query expressions for relational data |
POP- Introduction to Programming Using ‘C’
OOP – Object Oriented Programming
DBMS – Database Management System
RDBMS – Relational Database Management System
Join Now: Data Warehousing and Data Mining