Database Management System (DBMS)
Relational Calculus – A Non-Procedural Query Language

Relational Calculus is a non-procedural query language used in databases. Unlike Relational Algebra, which tells how to get the result (step-by-step), Relational Calculus tells what data to retrieve, without specifying how to do it.

There are two main types:

 

  1. Tuple Relational Calculus (TRC)
  2. Domain Relational Calculus (DRC)

 

Let’s look at both in detail.


1. Tuple Relational Calculus (TRC)

Tuple Relational Calculus is based on the use of tuples (rows) as variables. It expresses queries in the form of predicates (conditions) that a tuple must satisfy.

 

General Format:
{ t | P(t) }
  • t is a tuple variable.
  • P(t) is a predicate (condition) applied to t.

 

This notation means:
“Retrieve all tuples t such that the predicate P(t) is true.”


Example:

Suppose we have a Student table with attributes (Name, Age, Dept).
To find names of students in the “CS” department:

 

{ t.Name | t ∈ Student AND t.Dept = 'CS' }

 

Explanation:

  • t ∈ Student means tuple t comes from the Student relation.
  • t.Dept = 'CS' is the condition.
  • We are projecting only the Name attribute.

2. Domain Relational Calculus (DRC)

Domain Relational Calculus uses domain variables (i.e., variables that range over individual attribute values—not whole tuples).

 

General Format:
{ <x1, x2, ..., xn> | P(x1, x2, ..., xn) }
  • Each variable represents a column value (not the full row).
  • P(x1, x2, ..., xn) is a condition on those values.

 

Example:

From the same Student(Name, Age, Dept) table, to find the names of students in the “CS” department:

{ <N> | ∃ A ∃ D (Student(N, A, D) AND D = 'CS') }

 

Explanation:
  • N, A, D are domain variables for Name, Age, Dept.
  • We are selecting only the N (name) values.
  • The predicate ensures that the tuple (N, A, D) exists in the Student table and that D = 'CS'.

Key Differences Between TRC and DRC

Feature Tuple Relational Calculus (TRC) Domain Relational Calculus (DRC)
Variables represent Whole tuples (rows) Individual field values (columns)
Format `{ t P(t) }`
Style Closer to logic with tuple-based view Attribute-wise logical statements
Focus Tuples and their properties Specific fields and domain values

Relational Calculus is used to state what result we want without specifying how to get it.

 

It is based on predicate logic and helps in theoretical understanding and query formulation.

 

Both TRC and DRC form the theoretical foundation for high-level query languages like SQL.

0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.