Download presentation
Presentation is loading. Please wait.
Published byKerry Watson Modified over 9 years ago
1
1 CS 430 Database Theory Winter 2005 Lecture 6: Relational Calculus
2
2 What is the Relational Calculus? Answer: A non-procedural way to specify relational queries Relational algebra provides a procedural way to specify queries Why both? History SQL resembles Relational Calculus Relational Calculus came first Way to compare the power of various query languages
3
3 Tuple and Domain Relational Calculus Two forms of Relational Calculus: Tuple: Predicates on tuples Domain: Predicates on attributes Relational Calculus (without qualification) refers to the Tuple Relational Calculus
4
4 Tuple Relational Calculus Example: { t.FNAME, t.LNAME | EMPLOYEE(t) AND t.SALARY > 50000 } General: { t 1.A 1, …, t n.A n | COND(t 1, …, t n+k ) } t i are tuple variables A i are attributes COND is a condition or formula
5
5 Formulas Atoms R(t) where R is a relation and t is a tuple variable True if the tuple t is a tuple of the relation R x y, where x and y are either t.A i, an attribute, or c, a constant, and is a comparison operator Conditions (aka Formulas) Atoms Boolean combinations (AND, OR, NOT) of formulas Existential and Universal Quantifiers
6
6 Existential and Universal Quantifiers ( t) (F) “For all t, F is True” True if F is True for any possible tuple assigned to a free occurrence of t in F ( t) (F) “There exists t such that F is True” True if F is True for some tuple assigned to a free occurrence of t in F t is a tuple variable F is a formula
7
7 Safe Expressions A safe expression is one guaranteed to yield a finite number of tuples Non-safe expression: { t | NOT( EMPLOYEE(t)) } Domain of an expression: All values that exist in any tuple in the relations referenced in the expression and all constants used in the expression An expression is safe if all resulting values are from the domain of the expression Note that by definition this is a finite collection Usual use: All tuples t are qualified by an atom of the form R(t)
8
8 Domain Relational Calculus { x 1, …, x n | COND(x 1, …, x n+k ) } x i are value variables COND is a condition or formula Same structure as formula for Tuple Relational Calculus, except: R(x 1, …, x n ), where R is a relation, is True if is a tuple of R Example: { q, s | ( r) ( t) ( u) ( v) ( w) ( x) ( y) ( z) EMPLOYEE(qrstuvwxyz) AND x > 50000 } Shorthand { qs | EMPLOYEE(qrstuvwxyz) AND x > 50000 }
9
9 Relationally Complete A query language is “Relationally Complete” if it has the power of the Relational Calculus The Basic Relational Algebra (one with the original operations) is equivalent in power to the Relational Calculus Any expression in the Basic Relational Algebra has a corresponding expression in either Relational Calculus Any Safe expression in Relational Calculus has a corresponding expression in the Relational Algebra Note that the Relational Calculus (as given here) doesn’t include equivalents to EXTEND and AGGREGATION
10
10 Examples
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.