©Silberschatz, Korth and Sudarshan3.1Database System Concepts Calculus Objectives  Tuple Calculus  Domain Calculus  QBE & SQL  Related Examples.

Slides:



Advertisements
Similar presentations
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Advertisements

Relational Calculus and Datalog
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
RELATIONAL CALCULUS Rohit Khokher. INTRODUCTION Relational calculus is a formal query language where the queries are expressed as variables and formulas.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
E-R Diagram for a Banking Enterprise
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Relational Calculus Ameetinder Singh CS 157A. Tuple Relational Calculus  non-procedural query language as compared to relational algebra that is procedural.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Outer Join Aggregate Functions.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
SQL Structured Query Language Meizhen Huang. Content (4.1 – 4.4) Background Parts of SQL Basic Structure Set Operations Aggregate Functions.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
MySQL Tutorial (2) Introduction to Database. Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city)
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan1Database System Concepts Tuple and Domain Calculus Tuple Relational Calculus Domain Relational Calculus.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Chapters 2 & 6 The Relational Model. 2  A tabular data structure  Tables (relations) with unique names  rows (tuples/entities/records)  columns (attributes/fields)
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Null Values It is possible for tuples to have a null value for some of their attributes The.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Banking Example  branch (branch-name, branch-city, assets)  customer (customer-name, customer-street,
Chapter 5: Other Relational Languages. 5.2 Chapter 5: Other Relational Languages Tuple Relational Calculus Domain Relational Calculus Query-by-Example.
Relational Model: Examples. Banking Example branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) account.
Relational Algebra Instructor: Mohamed Eltabakh 1.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model III (based on notes by Silberchatz,Korth, and.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Outer Join n An extension of the join operation that avoids loss.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Department of Computer Science, HKUST 1 Comp 231 Database Management Systems Comp 231 Database Management Systems 3. Relational Data Model.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
Computing & Information Sciences Kansas State University Tuesday, 13 Feb 2007CIS 560: Database System Concepts Lecture 12 of 42 Tuesday, 13 February 2007.
Computing & Information Sciences Kansas State University Thursday, 08 Feb 2007CIS 560: Database System Concepts Lecture 11 of 42 Thursday, 08 February.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
Midterm 2 Revision Prof. Sin-Min Lee Department of Mathematics and Computer Science San Jose State University.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Query Languages Tuple Relational Calculus Domain Relational Calculus.
ICOM 5016 – Introduction to Database Systems Lecture 8 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Example.
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 5 Other Relational Languages.
Chapter 2: Relational Model II Relational Algebra basics Relational Algebra basics.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 5: Other Relational Languages.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Computing & Information Sciences Kansas State University Wednesday, 17 Sep 2008CIS 560: Database System Concepts Lecture 9 of 42 Wednesday, 18 September.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 5: Other Relational Languages.
Relational Algebra HW2 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Week 3: Relational Model Structure of Relational Databases Relational Algebra Extended Relational-Algebra-Operations.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Temple University – CIS Dept. CIS616– Principles of Database Systems V. Megalooikonomou Relational Model (based on notes by Silberchatz,Korth, and Sudarshan.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure”
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan Chapter 2: Relational Model.
CS 480: Database Systems Lecture 16 February 20,2013.
Chapter 6: Formal Relational Query Languages
Chapter 27: Formal-Relational Query Languages
Presentation transcript:

©Silberschatz, Korth and Sudarshan3.1Database System Concepts Calculus Objectives  Tuple Calculus  Domain Calculus  QBE & SQL  Related Examples

©Silberschatz, Korth and Sudarshan3.2Database System Concepts 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

©Silberschatz, Korth and Sudarshan3.3Database System Concepts 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 is 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

©Silberschatz, Korth and Sudarshan3.4Database System Concepts 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)

©Silberschatz, Korth and Sudarshan3.5Database System Concepts 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 Notice that a relation on schema [loan-number] is implicitly defined by the query R={t |  s  loan (t[loan-number] = s[loan-number]  s [amount]  1200)} R={t | t  loan  t [amount]  1200}

©Silberschatz, Korth and Sudarshan3.6Database System Concepts Example Queries Find the names of all customers having a loan, an account, or both at the bank R={t |  s  borrower( t[customer-name] = s[customer-name])   u  depositor( t[customer-name] = u[customer-name])} Find the names of all customers who have a loan and an account at the bank R={t |  s  borrower( t[customer-name] = s[customer-name])   u  depositor( t[customer-name] = u[customer-name])}

©Silberschatz, Korth and Sudarshan3.7Database System Concepts Example Queries Find the names of all customers having a loan at the Perryridge branch T={t |  s  borrower( t[customer-name] = s[customer-name]   u  loan(u[branch-name] = “Perryridge”  u[loan-number] = s[loan-number]))  not  v  depositor (v[customer-name] = t[customer-name]) } Find the names of all customers who have a loan at the Perryridge branch, but no account at any branch of the bank T={t |  s  borrower(t[customer-name] = s[customer-name]   u  loan(u[branch-name] = “Perryridge”  u[loan-number] = s[loan-number]))}

©Silberschatz, Korth and Sudarshan3.8Database System Concepts Example Queries Find the names of all customers having a loan from the Perryridge branch, and the cities they live in T={t |  s  loan(s[branch-name] = “Perryridge”   u  borrower (u[loan-number] = s[loan-number]  t [customer-name] = u[customer-name])   v  customer (u[customer-name] = v[customer-name]  t[customer-city] = v[customer-city]))} Alternate T={t |  s  borrower( t[customer-name]=s[customer-name]   u  loan(u[branch-name]= “Perryridge”  s[loan-number]=u[loan-number])   y  customer(y[customer-name]=s[customer-name]  t[customer-city]=y[customer-city]))}

©Silberschatz, Korth and Sudarshan3.9Database System Concepts Example Queries Find the names of all customers who have an account at all branches located in Brooklyn (Example of Division): R={t |  c  customer (t[customer-name] = c[customer-name])   s  branch(s[branch-city] = “Brooklyn”   u  account ( s[branch-name] = u[branch-name]   d  depositor ( t[customer-name] = d[customer-name]  d [account-number] = u[account-number] )) )}

©Silberschatz, Korth and Sudarshan3.10Database System Concepts Safety of Expressions It is possible to write tuple calculus expressions that generate infinite relations. For example, {t |  t  r} results in an infinite relation if the domain of any attribute of relation r is infinite To guard against the problem, we restrict the set of allowable expressions to safe expressions. An expression {t | P(t)} in the tuple relational calculus is safe if every component of t appears in one of the relations, tuples, or constants that appear in P  NOTE: this is more than just a syntax condition.  E.g. { t | t[A]=5  true } is not safe --- it defines an infinite set with attribute values that do not appear in any relation or tuples or constants in P.

©Silberschatz, Korth and Sudarshan3.11Database System Concepts Domain Relational Calculus A nonprocedural query language equivalent in power to the tuple relational calculus Each query is an expression of the form: {  x 1, x 2, …, x n  | P(x 1, x 2, …, x n )}  x 1, x 2, …, x n represent domain variables  P represents a formula similar to that of the predicate calculus

©Silberschatz, Korth and Sudarshan3.12Database System Concepts Example Queries Find the loan-number, branch-name, and amount for loans of over $1200 T={  c, a  |  l (  c, l   borrower   b(  l, b, a   loan  b = “Perryridge”))} Or T={  c, a  |  l, b (  c, l   borrower   l, b, a   loan  b = “Perryridge”)} Or T= {  c, a  |  l (  c, l   borrower   l, “Perryridge”, a   loan)} Find the names of all customers who have a loan from the Perryridge branch and the loan amount: R={  c  |  l, b, a (  c, l   borrower   l, b, a   loan  a > 1200)} Find the names of all customers who have a loan of over $1200 S={  l, b, a  |  l, b, a   loan  a > 1200}

©Silberschatz, Korth and Sudarshan3.13Database System Concepts Example Queries Find the names of all customers having a loan, an account, or both at the Perryridge branch: R={  c  |  s, n (  c, s, n   customer)   x,y,z(  x, y, z   branch  y = “Brooklyn”)   a,b(  a, x, b   account   c,a   depositor)} Find the names of all customers who have an account at all branches located in Brooklyn: R={  c  |  l, b,a (  c, l   borrower   l, b, a   loan  b = “Perryridge”)   a,b,n(  c, a   depositor   a, b, n   account  b = “Perryridge”)}

©Silberschatz, Korth and Sudarshan3.14Database System Concepts Safety of Expressions {  x 1, x 2, …, x n  | P(x 1, x 2, …, x n )} is safe if all of the following hold: 1.All values that appear in tuples of the expression are values from dom(P) (that is, the values appear either in P or in a tuple of a relation mentioned in P). 2.For every “there exists” subformula of the form  x (P 1 (x)), the subformula is true if and only if there is a value of x in dom(P 1 ) such that P 1 (x) is true. 3. For every “for all” subformula of the form  x (P 1 (x)), the subformula is true if and only if P 1 (x) is true for all values x from dom (P 1 ).

©Silberschatz, Korth and Sudarshan3.15Database System Concepts QBE & SQL QBE (Query By Examples)  Visual method for building queries SQL  Command line method for building queries Exercise: Get a list of customer names who are Borrowers in customer city ‘Dhahran’

©Silberschatz, Korth and Sudarshan3.16Database System Concepts Result of  branch-name = “Perryridge” (loan)

©Silberschatz, Korth and Sudarshan3.17Database System Concepts Loan Number and the Amount of the Loan

©Silberschatz, Korth and Sudarshan3.18Database System Concepts Names of All Customers Who Have Either a Loan or an Account

©Silberschatz, Korth and Sudarshan3.19Database System Concepts Customers With An Account But No Loan

©Silberschatz, Korth and Sudarshan3.20Database System Concepts Result of borrower  loan

©Silberschatz, Korth and Sudarshan3.21Database System Concepts Result of  branch-name = “Perryridge” (borrower  loan)

©Silberschatz, Korth and Sudarshan3.22Database System Concepts Result of  customer-name

©Silberschatz, Korth and Sudarshan3.23Database System Concepts Result of the Subexpression

©Silberschatz, Korth and Sudarshan3.24Database System Concepts Largest Account Balance in the Bank

©Silberschatz, Korth and Sudarshan3.25Database System Concepts Customers Who Live on the Same Street and In the Same City as Smith

©Silberschatz, Korth and Sudarshan3.26Database System Concepts Customers With Both an Account and a Loan at the Bank

©Silberschatz, Korth and Sudarshan3.27Database System Concepts Result of  customer-name, loan-number, amount (borrower loan)

©Silberschatz, Korth and Sudarshan3.28Database System Concepts Result of  branch-name (  customer-city = “Harrison” ( customer account depositor))

©Silberschatz, Korth and Sudarshan3.29Database System Concepts Result of  branch-name (  branch-city = “Brooklyn” (branch))

©Silberschatz, Korth and Sudarshan3.30Database System Concepts Result of  customer-name, branch-name (depositor account)

©Silberschatz, Korth and Sudarshan3.31Database System Concepts The credit-info Relation

©Silberschatz, Korth and Sudarshan3.32Database System Concepts Result of  customer-name, (limit – credit-balance) as credit-available (credit-info).

©Silberschatz, Korth and Sudarshan3.33Database System Concepts The pt-works Relation

©Silberschatz, Korth and Sudarshan3.34Database System Concepts The pt-works Relation After Grouping

©Silberschatz, Korth and Sudarshan3.35Database System Concepts Result of branch-name  sum(salary) (pt-works)

©Silberschatz, Korth and Sudarshan3.36Database System Concepts Result of branch-name  sum salary, max(salary) as max-salary (pt-works)

©Silberschatz, Korth and Sudarshan3.37Database System Concepts The employee and ft-works Relations

©Silberschatz, Korth and Sudarshan3.38Database System Concepts The Result of employee ft-works

©Silberschatz, Korth and Sudarshan3.39Database System Concepts The Result of employee ft-works

©Silberschatz, Korth and Sudarshan3.40Database System Concepts Result of employee ft-works

©Silberschatz, Korth and Sudarshan3.41Database System Concepts Result of employee ft-works

©Silberschatz, Korth and Sudarshan3.42Database System Concepts Tuples Inserted Into loan and borrower

©Silberschatz, Korth and Sudarshan3.43Database System Concepts Names of All Customers Who Have a Loan at the Perryridge Branch

©Silberschatz, Korth and Sudarshan3.44Database System Concepts E-R Diagram

©Silberschatz, Korth and Sudarshan3.45Database System Concepts The branch Relation

©Silberschatz, Korth and Sudarshan3.46Database System Concepts The loan Relation

©Silberschatz, Korth and Sudarshan3.47Database System Concepts The borrower Relation