Domain Relational Calculus (DRC)

 

Domain Relational Calculus (DRC)

1. What is Domain Relational Calculus?

Domain Relational Calculus is a formal, nonprocedural query language used in the relational model of databases.

  • It specifies what data to retrieve, not how to retrieve it

  • It is based on mathematical logic (predicate calculus)

  • It is equivalent in expressive power to:

    • Tuple Relational Calculus (TRC)

    • Basic Relational Algebra (for safe expressions)

Unlike tuple relational calculus, variables in domain calculus range over individual attribute values (domains) rather than entire tuples.


2. Difference Between Tuple and Domain Relational Calculus

AspectTuple Relational Calculus (TRC)    Domain Relational Calculus (DRC)
Variables range over    Tuples        Individual attribute values
Variable type    Tuple variables (t, e, p)        Domain variables (x, y, z)
Query focus    Whole rows        Attribute values
SQL foundation    Yes (main basis)        Indirect (via QBE)

3. General Form of a Domain Relational Calculus Expression

A domain relational calculus expression has the form:

{x1,x2,,xnCOND(x1,x2,,xn,xn+1,,xn+m)}\{x_1, x_2, \ldots, x_n \mid COND(x_1, x_2, \ldots, x_n, x_{n+1}, \ldots, x_{n+m})\}

Where:

  • x1,x2,,xnx_1, x_2, \ldots, x_n are free domain variables (appear in the result)

  • The variables after the bar | are used in conditions

  • COND is a Boolean formula (TRUE or FALSE)


4. Domain Variables

  • Domain variables represent single values from attribute domains

  • Lowercase letters are typically used:
    x, y, z, q, r, s, …

  • To produce a result relation of degree n, you must specify n free domain variables


5. Atoms in Domain Relational Calculus

A formula is built from atoms. There are three types:

1. Relation Atoms

R(x1,x2,,xn)R(x_1, x_2, \ldots, x_n)
  • Means: ⟨x₁, x₂, …, xₙ⟩ is a tuple in relation R

  • Example:

EMPLOYEE(q r s t u v w x y z)

2. Comparison Between Variables

xi  op  xjx_i \; op \; x_j
  • op ∈ {=, <, ≤, >, ≥, ≠}

  • Example:

m = z

(used as a join condition)


3. Comparison with Constants

xi  op  cx_i \; op \; c
  • Example:

l = 'Research'

(used as a selection condition)


6. Logical Operators

Atoms can be combined using:

  • AND

  • OR

  • NOT

Just like in predicate logic.


7. Quantifiers in Domain Relational Calculus

Two quantifiers are used:

Existential Quantifier (∃)

  • Means “there exists”

  • TRUE if at least one value satisfies the condition

Universal Quantifier (∀)

  • Means “for all”

  • TRUE only if the condition holds for every possible value

Example:

(∃x)(DEPENDENT(x) AND x = t)

8. Free and Bound Variables

  • Free variables:

    • Appear to the left of the bar (|)

    • Determine the output

  • Bound variables:

    • Quantified using ∃ or ∀

    • Used only for conditions


9. Example Queries

Example 1: Employee birth date and address for “John B. Smith”

{u, v | EMPLOYEE('John', 'B', 'Smith', t, u, v, w, x, y, z)}
  • u → Bdate

  • v → Address

  • Other variables are implicitly existentially quantified


Example 2: Employees with no dependents

{q, s | (∃t)(EMPLOYEE(q r s t u v w x y z) AND NOT (∃l)(DEPENDENT(l m n o p) AND t = l))}

This means:

Select employees for whom no dependent exists


10. Safety of Domain Relational Calculus Expressions

A safe expression:

  • Produces a finite result

  • All output values come from:

    • Constants in the query, or

    • Values in the referenced relations

Unsafe Example:

{x | NOT(EMPLOYEE(x))}

This is unsafe because it may return infinitely many values outside the database.

✅ All practical queries must be safe


11. Relationship to QBE (Query By Example)

  • Domain relational calculus is the formal foundation of QBE

  • QBE:

    • Is a graphical query language

    • Was developed at IBM

    • Uses domain variables implicitly

  • QBE ideas influenced many modern query tools


12. Key Points to Remember 

  • Domain Relational Calculus:

    • Uses domain (attribute) variables

    • Is nonprocedural

    • Is based on predicate logic

  • Equivalent in power to:

    • Tuple Relational Calculus

    • Basic Relational Algebra (for safe queries)

  • Uses:

    • Logical operators

    • Quantifiers

    • Selection and join conditions

Comments

Popular posts from this blog

Database Management Systems DBMS PCCST402 Semester 4 KTU CS 2024 Scheme

Data Models, Schemas and Instances

Introduction to Database Management System -DBMS