The Domain Relational Calculus
- Domain variables take on values from an attribute’s domain, rather than values for an entire tuple.
- An expression is of the form
where the represent domain variables, and is a formula.
- An atom in the domain relational calculus is of the following forms
- where is a relation on attributes, and , are domain variables or constants.
- , where and are domain variables, and is a comparison operator.
- , where c is a constant.
- Formulae are built up from atoms using the following rules:
- An atom is a formula.
- If is a formula, then so are and .
- If and are formulae, then so are , and .
- If is a formula where x is a domain variable, then so are and .
- Find branch name, loan number, customer name and amount for loans of over $1200.
- Find all customers who have a loan for an amount > than $1200.
- Find all customers having a loan from the SFU branch, and the city in which they live.
- Find all customers having a loan, an account or both at the SFU branch.
- Find all customers who have an account at all branches located in Brooklyn.
If you find this example difficult to understand, try rewriting this expression using implication, as in the tuple relational calculus example. Here’s my attempt:
I’ve used two letter variable names to get away from the problem of having to remember what stands for.
- As in the tuple relational calculus, it is possible to generate infinite expressions. The solution is similar for domain relational calculus-restrict the form to safe expressions involving values in the domain of the formula.
- All three of the following are equivalent:
- The relational algebra.
- The tuple relational calculus restricted to safe expressions.
- The domain relational calculus restricted to safe expressions.