Outline Tuple Relational Calculus Domain Relational Calculus ■ Datalog Database System Concepts-7th Edition 27.2 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 27.2 ©Silberschatz, Korth and Sudarshan th Edition Outline ▪ Tuple Relational Calculus ▪ Domain Relational Calculus ▪ Datalog
Tuple Relational Calculus Database System Concepts -7th Edition 27.3 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 27.3 ©Silberschatz, Korth and Sudarshan th Edition Tuple Relational Calculus
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 f e r denotes that tuple t is in relation r P is a formula similar to that of the predicate calculus Database System Concepts-7th Edition 27.4 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 27.4 ©Silberschatz, Korth and Sudarshan th Edition 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 Set of attributes and constants Set of comparison operators:(e.g,<,≤,=,≠,>,≥) ■ Set of connectives:and (A),or (v),not ( ■Implication(→):x→y,if x if true,then y is true X→y=XVy Set of quantifiers: ·3t∈r(Q(t)="there exists”a tuple in t in relation r such that predicate Q(t)is true 。tt∈r(Q(t))=Q is true“for all"tuples t in relation r Database System Concepts-7th Edition 27.5 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 27.5 ©Silberschatz, Korth and Sudarshan th Edition Predicate Calculus Formula ▪ Set of attributes and constants ▪ Set of comparison operators: (e.g., , , =, , , ) ▪ Set of connectives: and (), or (v)‚ not () ▪ Implication (): x y, if x if true, then y is true x y x v y ▪ 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
Example Queries Find the ID,name,dept_name,salary for instructors whose salary is greater than $80,000 {t|t e instructor^t[salary >80000) Notice that a relation on schema (ID,name,dept_name,salary)is implicitly defined by the query As in the previous query,but output only the /D attribute value (t3s einstructor (t [ID ]=s [ID ]^s [salary ]>80000)) Notice that a relation on schema(/D)is implicitly defined by the query Database System Concepts-7th Edition 27.6 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 27.6 ©Silberschatz, Korth and Sudarshan th Edition Example Queries ▪ Find the ID, name, dept_name, salary for instructors whose salary is greater than $80,000 ▪ As in the previous query, but output only the ID attribute value {t | s instructor (t [ID ] = s [ID ] s [salary ] 80000)} {t | t instructor t [salary ] 80000} Notice that a relation on schema (ID) is implicitly defined by the query Notice that a relation on schema (ID, name, dept_name, salary) is implicitly defined by the query