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
| Aspect | Tuple 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:
Where:
-
are free domain variables (appear in the result)
-
The variables after the bar
|are used in conditions -
CONDis 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
-
Means: ⟨x₁, x₂, …, xₙ⟩ is a tuple in relation R
-
Example:
2. Comparison Between Variables
-
op ∈ {=, <, ≤, >, ≥, ≠} -
Example:
(used as a join condition)
3. Comparison with Constants
-
Example:
(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:
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→ Bdate -
v→ Address -
Other variables are implicitly existentially quantified
Example 2: Employees with no dependents
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:
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
Post a Comment