Domain Relational Calculus in DBMS (original) (raw)

Last Updated : 26 Jul, 2025

Domain Relational Calculus (DRC) is a formal query language for relational databases. It describes queries by specifying a set of conditions or formulas that the data must satisfy. These conditions are written using domain variables and predicates, and it returns a relation that satisfies the specified conditions.

A general form of a DRC query is written as:

{ < x1, x2, x3, ..., xn > | P (x1, x2, x3, ..., xn ) }

where, <x1, x2, x3, ..., xn> represents resulting domains variables and P (x1, x2, x3, ..., xn) represents the condition or formula equivalent to the Predicate calculus.

The query returns a relation where each tuple consists of values for the domain variables x1,x2,…,xn such that the predicate PPP is true.

**Key Characteristics of DRC:

**Components of Domain Relational Calculus (DRC)

**1. Domain Variables

Domain variables represent the attributes (fields) that will appear in the resulting relation of the query. These variables are the **placeholders that will hold the actual values in the result.

**2. Predicate

A predicate is a **logical condition or **formula that the data must satisfy. It is expressed using comparison operators, connectives, and quantifiers.

**3. Quantifiers

Quantifiers are used to express the scope of a query:

**4. Domains and Relations

A domain refers to a specific set of values (like integers, strings) that a variable can take. A relation is a table in the database, and the tuples in the relation represent data that matches the query conditions.

**Writing Queries in Domain Relational Calculus (DRC)

Writing a query in DRC involves describing the desired result by specifying the domain variables and predicates that define the conditions the data must meet. Below are examples:

**Table 1: Customer

Customer Name Street City
Debomit Kadamtala Alipurduar
Sayantan Udaypur Balurghat
Soumya Nutanchati Bankura
Ritu Juhu Mumbai

**Table 2: Loan

Loan Number Branch Name Amount
L01 Main 200
L03 Main 150
L10 Sub 90
L08 Main 60

**Table 3: Borrower

Customer Name Loan Number
Ritu L01
Debomit L08
Soumya L03

Example 1: Finding Loans with Amount >= 100

To find all loans with an amount greater than or equal to 100, we use the following query in DRC:

{≺l, b, a≻ | ≺l, b, a≻ ∈ loan ∧ (a ≥ 100)}

**Resulting relation:

Loan Number Branch Name Amount
L01 Main 200
L03 Main 150

This query specifies that the result will contain the loan number (l), branch name (b), and amount (a) from the loan relation where the amount is greater than or equal to 100.

**Example 2: Finding Loan Numbers >= 150

To find loan numbers where the amount is greater than or equal to 150, we write:

{≺l≻ | ∃ b, a (≺l, b, a≻ ∈ loan ∧ (a ≥ 150))}

**Resulting Relation:

Loan Number
L01
L03

**Example 3: Finding Customers with Loans from "Main" Branch

To find the names of customers who have a loan at the "Main" branch, along with their loan amounts:

{≺c, a≻ | ∃ l (≺c, l≻ ∈ borrower ∧ ∃ b (≺l, b, a≻ ∈ loan ∧ (b = “Main”)))}

**Resulting relation:

Customer Name Amount
Ritu 200
Debomit 60
Soumya 150

**Advantages of Domain Relational Calculus (DRC)

  1. **Declarative Nature: DRC allows the user to describe _what data they need without having to specify _how to retrieve it. This makes it easier to write queries and understand them.
  2. **Mathematical Foundation: Being based on predicate logic, DRC provides a solid theoretical foundation for relational databases.
  3. **Non-Procedural: Unlike procedural query languages, DRC focuses on describing the result, not the procedure to get it.
  4. **Flexible and Powerful: It supports complex queries involving multiple relations, predicates, and conditions.

**Limitations of Domain Relational Calculus (DRC)

  1. **Complexity: DRC can be difficult to use for complex queries due to its reliance on logical formulas. It requires a good understanding of predicate calculus.
  2. **No Specification of Query Execution: Since it is non-procedural, DRC does not specify how queries should be executed, which can sometimes lead to inefficiencies in query execution.
  3. **Lack of Optimization: Unlike SQL, DRC does not provide built-in optimization mechanisms, meaning that users must rely on the DBMS for query optimization.
  4. **Less User-Friendly: As a formal query language, DRC is not as user-friendly as SQL, which is more widely used and has a simpler syntax.

DRC vs TRC (Tuple Relational Calculus) Comparison

Aspect Domain Relational Calculus Tuple Relational Calculus
Query Focus Focuses on domain variables (attributes) Focuses on tuple variables (rows)
Syntax Describes queries using domain variables and predicates Describes queries using tuple variables and predicates
Usage More abstract; deals with individual attributes Deals with entire rows (tuples) in a relation
Query Writing Style Less intuitive; requires logical expressions involving attributes More intuitive; uses variables representing tuples
Complexity Can be more complex due to the abstraction of variables Simpler to understand and write compared to DRC

While both DRC and TRC are non-procedural query languages that allow users to query relational databases, DRC focuses on individual attributes (domain variables), while TRC focuses on tuples (rows). TRC is more widely used because it is more intuitive and easier to understand.