←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Notes

Domain Relational Calculus (DRC) & Safety of Expressions

Study material and explanations for Unit 3

Domain Relational Calculus (DRC) and Safety of Expressions

What is Domain Relational Calculus (DRC)? (In Simple Words)

In Tuple Relational Calculus (TRC), our variables range over entire tuples (rows) of a relation.

In Domain Relational Calculus (DRC), our variables range over individual attribute values (domains of columns) rather than entire rows!

DRC serves as the theoretical foundation behind visual visual query interfaces, such as IBM’s QBE (Query By Example).


1. Syntax and Structure of a DRC Query

A query in DRC is written in the following mathematical format:

Structure of a DRC Expression
< x1, x2, ..., xn >
Domain Variables (Target Columns)
➔ \| (Such that) ➔
P(x1, x2, ..., xn)
Qualifying Predicate Formula
  • <x1, x2, ... xn>: Represents the domain variables whose values should appear in the resulting query output.
  • P(x1, x2, ... xn): A predicate condition consisting of atoms, logical connectives (∧, ∨, ¬), and quantifiers (∃, ∀).

2. Practical DRC Query Examples

Consider table STUDENT (Roll_No, Name, Branch, Marks, City).

Query 1: “Find the roll numbers and names of all students from ‘Indore’.”

  • We create domain variables for each column:
    • r for Roll_No
    • n for Name
    • b for Branch
    • m for Marks
    • c for City
  • DRC Expression:
    { <r, n> | <r, n, b, m, 'Indore'> ∈ STUDENT }
    (Notice how we directly substitute 'Indore' into the city position, and output <r, n>!)

Query 2: “Find names of students who scored more than 85 marks.”

  • DRC Expression:
    { <n> | ∃ r, b, m, c (<r, n, b, m, c> ∈ STUDENT ∧ m > 85) }

3. Comprehensive Comparison: TRC vs. DRC

Parameter Tuple Relational Calculus (TRC) Domain Relational Calculus (DRC)
Variable Scope Variables range over entire rows (tuples) Variables range over individual column values (domains)
Basic Syntax { t | P(t) } { <x1, x2, ...> | P(x1, x2, ...) }
Attribute Access Uses dot/bracket notation: t.Salary or t[Salary] Directly refers to domain variable: s
Practical Influence Theoretical foundation of SQL Theoretical foundation of QBE (Query By Example)
Quantification Quantifies entire tuples: ∃ s (...) Quantifies individual column variables: ∃ s, d (...)

4. Safety of Expressions (Safe vs. Unsafe Queries)

In theoretical relational calculus, it is possible to write mathematical expressions that produce an INFINITE number of result tuples! Such expressions are called Unsafe Expressions.

Example of an Unsafe Query:

Consider the TRC query: { t | ¬ (t ∈ STUDENT) }

  • What does this query mean? It asks for “every tuple in the entire universe that is NOT in the student table”.
  • It would return all books, cows, cars, integers, planets, and sentences ever spoken!
  • The computer’s memory would instantly crash trying to generate infinite rows.

The Concept of Domain of a Formula: dom(P)

  • The Domain of a formula P (written as dom(P)) is the set of all constant values that appear explicitly in the query P or in the relations referenced by P.
  • Definition of a Safe Expression:
    A relational calculus expression is SAFE if and only if all values appearing in the final output result are guaranteed to come strictly from the finite domain dom(P).

Database management systems automatically reject or disallow unsafe queries, ensuring that every executed query terminates in finite time with a finite result set.


5. Expressive Power: Codd’s Equivalence Theorem

A major milestone in computer science proved by Dr. E.F. Codd:

  • Codd’s Theorem: The expressive power of Relational Algebra is mathematically EQUIVALENT to the expressive power of Safe Relational Calculus.
  • Any query that can be written in Relational Algebra can also be written in Safe TRC and Safe DRC, and vice-versa!
  • A database query language is declared Relational Complete if it has at least the full expressive power of Relational Algebra.

💡 DAVV Exam Preparation Tips

5-Mark Question: “What is an Unsafe Expression in Relational Calculus? How is safety guaranteed?”

  • Define an unsafe query as an expression that yields an infinite result (e.g., { t | ¬ (t ∈ STUDENT) }).
  • Define dom(P) (the finite set of constants present in the query and tables).
  • Explain that a safe query guarantees all output values are strictly members of dom(P).

10-Mark Question: “Explain Domain Relational Calculus (DRC) with syntax and examples. Compare TRC and DRC across at least five parameters. State Codd’s Equivalence Theorem.”

  • Write down DRC syntax { <x1, x2, ...> | P(x1, x2, ...) }.
  • Provide the student query examples.
  • Provide the 5-point comparison table between TRC and DRC.
  • Explain Codd’s Theorem and the definition of Relational Completeness.