DBMS – Relational Algebra & Relational Calculus
Complete Notes · Operators · Joins · TRC · DRC · Quantifiers · Codd's Theorem · 75 MCQs
Introduction
Database Management Systems (DBMS) is one of the highest-scoring subjects in both GATE CSE and the Rajasthan Computer Teacher Recruitment Examination. Among all DBMS topics, Relational Algebra and Relational Calculus are repeatedly asked in objective as well as conceptual questions.
If you understand these two topics well, you can easily solve SQL-based questions, query processing problems, and theoretical questions. This guide explains every important concept in simple language and provides exam-oriented revision notes.
What is Relational Algebra?
Relational Algebra is a procedural query language used to retrieve data from a relational database.
It tells us how to retrieve the required data by applying a sequence of operations on one or more relations (tables).
Key Features
- Procedural language
- Based on set theory
- Input is one or more relations
- Output is always a relation
- Closed under operations
- Duplicate tuples are removed automatically
Basic Terminology
Before learning Relational Algebra, remember these basic database terms.
| Term | Meaning |
|---|---|
| Relation | Table |
| Tuple | Row |
| Attribute | Column |
| Domain | Allowed values of an attribute |
| Degree | Number of columns |
| Cardinality | Number of rows |
| Schema | Structure of a relation |
| Instance | Current data stored in the table |
| Primary Key | Unique identifier |
| Foreign Key | References another table's primary key |
Basic Operators of Relational Algebra
1. Selection (σ)
Selection retrieves only those rows that satisfy a specified condition.
σ Salary > 50000(Employee)
-- Equivalent SQL
SELECT *
FROM Employee
WHERE Salary > 50000;
2. Projection (π)
Projection retrieves only selected columns from a relation.
-- Equivalent SQL
SELECT Name, Salary
FROM Employee;
Selection vs Projection
| Selection | Projection |
|---|---|
| Selects rows | Selects columns |
| Uses σ | Uses π |
| Equivalent to WHERE | Equivalent to SELECT |
3. Union (∪)
Union combines tuples from two compatible relations.
Conditions for Union
- Same number of columns
- Same data types
- Same order of attributes
- Union compatible schema
Duplicates are removed automatically.
4. Set Difference (−)
Returns tuples present in the first relation but not in the second.
5. Intersection (∩)
Returns only the common tuples present in both relations.
6. Cartesian Product (×)
Produces every possible combination of tuples from two relations.
Formula: Total Rows = m × n
where: m = rows in first table, n = rows in second table
7. Rename Operator (ρ)
Rename changes the name of a relation or attribute.
Join Operations
Join is one of the most important topics in DBMS examinations. A Join combines related tuples from two relations.
| Join Type | Description |
|---|---|
| Theta Join (θ) | Uses comparison operators like <, >, ≤, ≥, =, ≠ |
| Equi Join | Uses only equality (=) operator. Duplicate join columns remain. |
| Natural Join | Automatically joins based on common attributes. Duplicates removed. |
| Left Outer Join | All rows from left table + matching rows from right + NULL |
| Right Outer Join | All rows from right table + matching rows from left |
| Full Outer Join | Every row from both tables |
| Self Join | Table joins with itself (e.g., Employee → Manager) |
⭐ Important: Natural Join removes duplicate join columns. Equi Join keeps them.
Division Operator (÷)
The Division operator answers "For All" type queries.
- Students who passed all subjects
- Employees who know all programming languages
Extended Relational Algebra
Common aggregate functions include:
- COUNT()
- SUM()
- AVG()
- MIN()
- MAX()
These are frequently used with GROUP BY and ORDER BY.
Relational Algebra and SQL
| Relational Algebra | SQL |
|---|---|
| Selection (σ) | WHERE |
| Projection (π) | SELECT |
| Union (∪) | UNION |
| Cartesian Product (×) | CROSS JOIN |
| Join (⨝) | JOIN |
| Difference (−) | EXCEPT / MINUS |
What is Relational Calculus?
Relational Calculus is a non-procedural query language.
Unlike Relational Algebra, it specifies what data is required instead of describing how to retrieve it.
Tuple Relational Calculus (TRC)
-- Example: Find employees with salary > 50000
{ t | Employee(t) AND t.salary > 50000 }
Domain Relational Calculus (DRC)
-- Example
{ <Name, Salary> | Employee(Name, Salary) AND Salary > 50000 }
TRC vs DRC
| Tuple Relational Calculus | Domain Relational Calculus |
|---|---|
| Uses tuple variables | Uses domain variables |
| Works on complete rows | Works on attribute values |
Quantifiers
Existential Quantifier (∃)
Meaning: "There exists"
Universal Quantifier (∀)
Meaning: "For all"
Safe and Unsafe Expressions
Safe Expression
- Produces a finite result
- Can be evaluated
Unsafe Expression
- Produces an infinite result
- Cannot be evaluated practically
Codd's Theorem ⭐⭐⭐⭐⭐
Statement: Every query that can be expressed in Relational Algebra can also be expressed in Relational Calculus, and vice versa.
Therefore, both have equal expressive power.
Relational Algebra vs Relational Calculus
| Relational Algebra | Relational Calculus |
|---|---|
| Procedural | Non-Procedural |
| Specifies HOW | Specifies WHAT |
| Based on operators | Based on predicate logic |
| Practical implementation | Theoretical foundation |
Frequently Asked Questions in GATE and Rajasthan Computer Teacher Exam
- Difference between Selection and Projection
- Difference between Natural Join and Equi Join
- Join types with examples
- Union compatibility conditions
- Cartesian Product formula
- Division operator applications
- Difference between Relational Algebra and Relational Calculus
- TRC vs DRC
- Safe vs Unsafe Expressions
- Degree vs Cardinality
- Primary Key vs Foreign Key
- Codd's Theorem
Quick Revision Table
Final Exam Tips
- Memorize all Relational Algebra symbols and their meanings.
- Practice converting SQL queries into Relational Algebra expressions.
- Focus on Join operations and Division operator, as they are frequently tested.
- Understand the difference between Relational Algebra and Relational Calculus rather than memorizing definitions.
- Revise Degree vs Cardinality, Primary Key vs Foreign Key, and Codd's Theorem before the exam.
🎯 Conclusion
"Relational Algebra and Relational Calculus form the theoretical foundation of relational databases and SQL. Mastering these concepts will not only improve your score in GATE CSE and the Rajasthan Computer Teacher Exam, but also strengthen your understanding of DBMS for interviews and software development. Consistent practice with previous-year questions and regular revision of these core concepts will significantly improve your performance in competitive examinations."
Loading questions...
परिणाम
बहुत अच्छा!
ऊपर 'पुनः प्रयास' बटन से दोबारा प्रयास करें