Download presentation
Presentation is loading. Please wait.
1
Dr. Alexandra I. Cristea http://www.dcs.warwick.ac.uk/~acristea/ CS 319: Theory of Databases: C6
2
… previous RA
3
(provisionary) Content 1.Generalities DB 2.Integrity constraints (FD revisited) 3.Temporal Data 4.Relational Algebra (revisited) 5.Query optimisation 6.Tuple calculus 7.Domain calculus 8.Query equivalence 9.The Askew Wall
4
Tuple Calculus non-procedural query language A query in TC is expressed as: {t|P(t)} where: t – set of tuples (also called free variable) P – predicate that is true for t (also called formula) Also: t[A] – value of tuple t on attribute A t r – means the tuple t is in relation r
5
Examples TC {t | t loan ^ t[amount] > 1200} {t | s loan (t[loan-number] = s[loan- number] ^ s[amount] > 1200)}
6
Domain calculus Uses domain variables to take values from an attributes domain, instead of tuple values is related to QBE language An expression in DC is of the form: { | P(x1,x2,…,xn)} where: x1,…xn are domain variables P is a formula
7
Example DC { | loan ^ a > 1200} { | b,a ( loan ^ a > 1200)}
8
Tuple Calculus A TC expression {t | P(t)} may give an infinite relation, e.g., { t | (t loan) } Define dom(P) as the set of all values referenced by P (e.g. litterals or relations) A TC expression {t | P(t)} is safe when all values appearing in the result are values from dom(P).
9
Queries in TC Translate the following questions (for the bank database) to the tuple calculus: –Give the name of customers that have a loan with a branch where they also have an account. –Give the name of customers who have a loan at a branch where they do not have an account. –Give the name of customers who have a loan at every branch where they have an account. –Give the name of customers who have loans only at branches where they have an account.
10
Library TC questions Give the name and department of borrowers, and the ISBN-number of the books of which they were the first borrower. Give the name and department of borrowers who have never borrowed the most recently purchased copy of a book. Give the title of books that are “present” in the library, reserved by someone, but not yet borrowed (by anyone).
11
Summary We have learned TC & DC We have learned to perform simple and more complex queries in TC & DC
12
… to follow Query equivalence
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.