In what situations would you use domain relational calculus over tuple
relational calculus?
Assuming you have access to the same operators on values of columns, any expression of the tuple relational calculus, domain predicate calculus or relational algebra can be transformed into one of the other. You can use any of them in a given situation.
The tuple calculus expression
{ t < c,... > | ∃ u ∈ U : ... t.c ... u.x ...}
describes the same set as the domain calculus expression
{ < c,... > | ∃ x,... : U(x,...) ∧ ... c ... x ...}.
"U" names a given relation and "u" names an arbitrary tuple from from it and "x,..." are its attributes. "U(x,...)" is called an atomic formula. "∃" is called a quantifier and means "there exists" or "for some".)
So to convert tuple calculus to domain calculus:
- Drop the name for a tuple in the result.
- Replace a quantified tuple name and relation name by a quantified list of its attribute names and an atomic formula using them.
- Drop dotted tuple names.
And to convert domain calculus to tuple calculus:
- Insert a name for a tuple in the result.
- Rearrange so that every quantified attribute list contains exactly the attributes of one relation and an atomic formula with that relation follows it.
- Replace a quantified list of a relation's attribute names and an atomic formula using them by some new quantified tuple name and the relation's name.
- Insert dotted tuple names in front of their attributes.
In addition, how would you express set differences in both?
An expression in either calculus describes a set of tuples. The set difference A \ B is the set of tuples that are in set A but that are not in set B. If relation R holds tuples where expressionR and relation S holds tuples where expressionS then R \ S = R MINUS S = tuples where expressionR ∧ ~ expressionS.
(It may help you to read this about building queries via natural language then converting to domain calculus then converting to relational algebra. It starts with a parameterized statement as the meaning of each given relation/table. Then it finds a combination of those to express a given query. Then it converts that expression to shorthand which is like domain calculus. (And like standard predicate logic aka predicate calculus but also.) To get relational tuple calculus you convert the domain calculus to tuple calculus as described above. In SQL, JOIN ON, CROSS JOIN and "," are much like tuple calculus while JOIN USING and NATURAL JOIN are like a mixture of both domain calculus and tuple calculus.)