Tuple and Domain Relational Calculus
Tuple and Domain Relational Calculus
Sample Queries
Finding
Sample queries(cont.)
Finding
Sample Queries(cont.)
The expression:
Formal Definition
As shown earlier, a tuple relational calculus expression is of the form
{t | P(t)}
Where P is a formula.
A formula may contain several tuple variables.
A tuple variable is said to be a free variable unless it is quantified by
a (there exists) or (for all).
Tuple variables that are quantified by or are called bound
variables.
For ex, in the expression:
t loan s customer(t[branch name] = s[branch name])
t is a free variable and s is a bound variable.
Formal definition(cont.)
1.
2.
3.
Building a formula
We build up a formula from atoms by using the
following rules.
An atom is a formula.
If P1 is a formula, then so are P1 and (P1).
If P1 and P2 are formulae, then so are P1 P2, P1 P2,
and P1 => P2.
If P1(s) is a formula containing a free tuple variable s,
and r is a relation, then
s r(P1(s)) and s (P1(s))
are also formulae
Formal Definition
A general
Example Queries
Find
Find all loan numbers for loans with an amount > 1200:
{<l> | b,a (<l,b,a> loan a > 1200)}
Example queries(cont.)
Safety of Expressions
As
Safety(cont.)
An expression:
{<x1,x2,.,xn> | P(x1,x2,.,xn)}
is safe if all of the following hold.
All values that appear in tuples of the expression are values
from dom(P).
For every there exists subformula of the form x(P1(x)),
the sub formula is true only if and only if there is a value x
in dom(P1) such that P1(x) is true.
For every for all subformula of the form x(P1(x)), the
subformula is true if and only if P1(x) is true for all values
of x from dom(P1).