Chapter :- 3 (English)
5. Relational Calculus
Relational Calculus
Relational Calculus is a non-procedural (declarative) query language used in relational databases.
It tells what data to retrieve, not how to retrieve it.
It is based on mathematical predicate logic and forms a theoretical foundation for SQL.
There are two types:
1. Tuple Relational Calculus (TRC)
Uses tuple variables that represent rows.
Example:
{ t | t ∈ Student AND t.age > 18 }
This means:
"Find all tuples t from Student where age > 18"
2. Domain Relational Calculus (DRC)
Uses domain variables that represent column values.
Example:
{ <name, age> | ∃ id (Student(id, name, age) AND age > 18) }
Advantages of Relational Calculus
✔ 1. Non-Procedural Language
Users specify only what they want, making it easier to write and understand.
✔ 2. Basis for SQL
SQL's declarative nature comes from relational calculus.
✔ 3. Higher Level of Abstraction
Focuses on logic, not operations—ideal for designing queries conceptually.
✔ 4. Concise and Clean
Calculus expressions are often shorter than relational algebra expressions.
✔ 5. DBMS Query Optimization
Since users don’t specify the execution steps, the DBMS can optimize the query on its own.
Disadvantages of Relational Calculus
1. Not User-Friendly for Complex Queries
Logical expressions can become difficult when queries involve many conditions.
2. May Produce Infinite Results
Unsafe expressions can generate infinite sets, so safety rules are needed.
3. Not Used Directly in DBMS
It is mainly theoretical; users work with SQL, not calculus.
4. Harder to Implement Internally
DBMS must convert calculus expressions into relational algebra, adding complexity.
5. Less Intuitive for Beginners
Logical notation can confuse students unfamiliar with predicate logic.