Tuple relational calculus (source code)

= Tuple relational calculus

<Tuple relational calculus> describes <database query>[query] answers by <predicate>[predicates] over <database> <database tuple>[tuples] rather than a sequence of storage operations. A set-builder expression $\{t:P(t)\}$ returns <database tuple>[tuples] satisfying a formula built from <database relation>[relation] membership, attribute comparisons, <logical connective>[logical connectives] and <quantifier>[quantifiers]. For example,
$$
\{t: \operatorname{Employee}(t)\land t.\mathrm{salary}>100\}
$$
selects employee <database tuple>[tuples] whose salary exceeds100. A join can be expressed using <existential quantification>[existentially quantified] <database tuple>[tuples] from two <database relation>[relations] and <equality (mathematics)>[equality] of their shared identifying attribute.

The formula needs a safety restriction. Over an unrestricted infinite value universe, a <database query>[query] such as $\{t:\neg\operatorname{Employee}(t)\}$ can demand infinitely many absent <database tuple>[tuples]. <Safe tuple relational calculus> restricts results to information grounded in the input and explicit <constant (mathematics)>[constants]. Under the usual finite-relation assumptions, its expressive power agrees with <relational algebra>. This gives a declarative <database query>[query] language while leaving the <database> system free to choose an efficient <database query plan>[query plan].