Chapter 5:Other Relational Languages Tuple Relational Calculus Domain Relational Calculus Query-by-Example(QBE) Datalog Database System Concepts-5th Edition,July 8,2005 5.2 @Silberschatz,Korth and Sudarshan
Database System Concepts - 5 5.2 ©Silberschatz, Korth and Sudarshan th Edition, July 8, 2005 Chapter 5: Other Relational Languages Tuple Relational Calculus Domain Relational Calculus Query-by-Example (QBE) Datalog
Tuple Relational Calculus A nonprocedural query language,where each query is of the form tP(t)) It is the set of all tuples t such that predicate P is true for f t is a tuple variable,t [A]denotes the value of tuple t on attribute A t e r denotes that tuple t is in relation r P is a formula similar to that of the predicate calculus Database System Concepts-5th Edition,July 8,2005 5.3 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 5.3 ©Silberschatz, Korth and Sudarshan th Edition, July 8, 2005 Tuple Relational Calculus A nonprocedural query language, where each query is of the form {t | P (t ) } It is the set of all tuples t such that predicate P is true for t t is a tuple variable, t [A ] denotes the value of tuple t on attribute A t r denotes that tuple t is in relation r P is a formula similar to that of the predicate calculus
Predicate Calculus Formula 1.Set of attributes and constants 2.Set of comparison operators:(e.g,<,≤,=,≠,>,≥) 3.Set of connectives:and (A),or (v),not ( 4.Implication(→:x→y,if x if true,then y is true X→y≡XVy 5.Set of quantifiers: 3ter(Q(t))="there exists"a tuple in t in relation r such that predicate Q(t)is true ∀ter(Q(t)≡Q is true“for all"tuples t in relation r Database System Concepts-5th Edition,July 8,2005 5.4 @Silberschatz,Korth and Sudarshan
Database System Concepts - 5 5.4 ©Silberschatz, Korth and Sudarshan th Edition, July 8, 2005 Predicate Calculus Formula 1. Set of attributes and constants 2. Set of comparison operators: (e.g., , , =, , , ) 3. Set of connectives: and (), or (v)‚ not () 4. Implication (): x y, if x if true, then y is true x y x v y 5. Set of quantifiers: t r (Q (t )) ”there exists” a tuple in t in relation r such that predicate Q (t ) is true t r (Q (t )) Q is true “for all” tuples t in relation r
Banking Example branch (branch name,branch city,assets customer(customer name,customer street,customer city account (account_number,branch_name,balance loan(loan number,branch name,amount depositor(customer name,account number borrower (customer name,loan number Database System Concepts-5th Edition,July 8,2005 5.5 @Silberschatz,Korth and Sudarshan
Database System Concepts - 5 5.5 ©Silberschatz, Korth and Sudarshan th Edition, July 8, 2005 Banking Example branch (branch_name, branch_city, assets ) customer (customer_name, customer_street, customer_city ) account (account_number, branch_name, balance ) loan (loan_number, branch_name, amount ) depositor (customer_name, account_number ) borrower (customer_name, loan_number )
Example Queries Find the loan number,branch name,and amount for loans of over $1200 {t tE loan ^t [amount ]1200) Find the loan number for each loan of an amount greater than $1200 {t |3s e loan (t [loan_number ]s [loan_number ]^s [amount ]>1200)} Notice that a relation on schema [loan number is implicitly defined by the query Database System Concepts-5th Edition,July 8,2005 5.6 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 5.6 ©Silberschatz, Korth and Sudarshan th Edition, July 8, 2005 Example Queries Find the loan_number, branch_name, and amount for loans of over $1200 Find the loan number for each loan of an amount greater than $1200 {t | s loan (t [loan_number ] = s [loan_number ] s [amount ] 1200)} Notice that a relation on schema [loan_number ] is implicitly defined by the query {t | t loan t [amount ] 1200}