603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 14 A First Course in Database Systems.

Slides:



Advertisements
Similar presentations
The Relational Calculus
Advertisements

1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
1 CSE 480: Database Systems Lecture 22: Query Optimization Reference: Read Chapter 15.6 – 15.8 of the textbook.
Dept. of Computer & Information Sciences
Employee database: Conceptual Schema in ERD Chapter 3, page 62.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 6- 1.
Slide Chapter 6 The Relational Algebra and Calculus.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Introduction to Database Systems 1 Relational Calculus Relational Model : Topic 2.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Rutgers University Relational Calculus 198:541 Rutgers University.
Chapter 4 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Banking Example  branch (branch-name, branch-city, assets)  customer (customer-name, customer-street,
Lecture 3 [Self Study] Relational Calculus
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
1 CS 430 Database Theory Winter 2005 Lecture 6: Relational Calculus.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
CS 380 Introduction to Database Systems Chapter 7: The Relational Algebra and Relational Calculus.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Relational Calculus. Non Procedural or Declarative Calculus has variables, constants, comparison ops, logical connectives and quantifiers. There are TWO.
Database Management Systems. NESTING OF QUERIES  Some queries require that existing values in the database be retrieved and then used in a comparison.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 17 A First Course in Database Systems.
Relational Algebra. 2 Outline  Relational Algebra Unary Relational Operations Relational Algebra Operations from Set Theory Binary Relational Operations.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
1 CSE 480: Database Systems Lecture 12: SQL (Nested queries and Aggregate functions)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1 CIS 611.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
The Relational Algebra and Calculus. Slide 6- 2 Chapter Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set.
The Relational Calculus (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe The Relational Calculus The main reference of this presentation is the textbook and PPT from : Elmasri.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Slide 6- 1 Additional Relational Operations Aggregate Functions and Grouping A type of request that cannot be expressed in the basic relational algebra.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 21 A First Course in Database Systems.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 11 A First Course in Database Systems.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems.
The Relational Algebra and The Relational Calculus
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 18 A First Course in Database Systems.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 16 A First Course in Database Systems.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Relational Calculus. Relational calculus query specifies what is to be retrieved rather than how to retrieve it. – No description of how to evaluate a.
Jun-Ki Min.  Based on predicate calculus ◦ Predicate  a function whose value is true or false  non-procedural ◦ A relational calculus expression creates.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Lecture # 10 July 10,2012 More SQL: Complex Queries, Triggers,
Relational Algebra. CENG 3512 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.
Chapter 4 The Relational Algebra and Calculus
Introduction to Relational Calculus Tuple Relational Calculus
CSE202 Database Management Systems
A First Course in Database Systems
CS580 Advanced Database Topics
The Relational Algebra and Relational Calculus
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
11/22/2018.
Session - 6 Sequence - 2 SQL: The Structured Query Language:
12/5/2018.
12/31/2018.
Relational Calculus and QBE
Introduction to Database Systems
Relational Calculus and QBE
SQL: Set Operations & Nested Queries. Presented by: Dr. Samir Tartir
Presentation transcript:

603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 14 A First Course in Database Systems

Relational Calculus Transforming the Universal (  ), and Existential(  ) Quantifiers ( Well-Known transformations from Mathematical Logic) : (  x) (P(x))  not (  x) (not(P(x))) (  x) (P(x))  not (  x) (not(P(x))) (  x) (P(x) and Q(x))  not (  x) (not(P(x)) or not (Q(x))) (  x) (P(x) or Q(x))  not (  x) (not(P(x)) and not (Q(x))) (  x) (P(x) or Q(x))  not (  x) (not(P(x)) and not (Q(x))) (  x) (P(x) and Q(x))  not (  x) (not(P(x)) or not (Q(x)))

Relational Calculus NOTICE: (  x) (P(x))  (  x) (P(x)) not (  x) (P(x))  not (  x) (P(x))

Relational Calculus The Existential(  ) and Universal(  ) Quantifiers: Truth Values for formulas with these quantifiers are described below: 1. If F is a formula, then so is (  t )(F), where t is a tuple variable. (  t )(F) is TRUE if the formula F evaluates to TRUE for some (at least one) tuple assigned to free occurrences of t in F; otherwise is (  t )(F) FALSE. 2. If F is a formula, then so is (  t )(F), where t is a tuple variable. (  t )(F) is TRUE if the formula F evaluates to TRUE for every tuple (in the universe) tuple assigned to free occurrences of t in F; otherwise is (  t )(F) FALSE.

Relational Calculus Concept of free and bound tuple variables: Informally, a tuple variable is bound if it is quantified, meaning that it appears in an (  t ) or (  t ) clause; otherwise, it is free.

Relational Calculus Formally, a tuple variable is free or bound according to the following rules: *An occurrence of a tuple variable in a formula F that is an atom is free in F *An occurrence of a tuple variable t is free or bound in a formula made up of logical connectives- ( F 1 and F 2 ), ( F 1 or F 2 ), not (F 1 ) and not ( F 2 ) - depending on whether it is free or bound in F 1 or F 2 (if it occurs in either).

Relational Calculus Formally, a tuple variable is free or bound according to the following rules(continued): *All free occurrences of a tuple variable t in F are bound in a formula F’ of the form F’ = (  t )(F) or (  t )(F). The tuple variable is bound to the quantifier specified in F’.

Relational Calculus The (  ) quantifier is called an existential quantifier because a formula (  t )(F) is TRUE if “there exists” some tuple that makes F TRUE. For the universal quantifier, (  t )(F) is TRUE if every possible tuple that can be assigned to free occurrences of t in F is substituted for t, and F is TRUE for every such substitution. It is called the universal (or for all) quantifier because every tuple in “the universe of” tuples must make F TRUE to make the quantified formula TRUE.

Relational Calculus EXAMPLE: F 1 :d.DNAME = “Research” F 2 :(  t )(d.DNUMBER = t.DNO) d is bound F 3 :(  d ) (d.MGRSSN = ‘ ’) The tuple variable d is free in both F 1 and F 2, whereas it is bound to the universal quantifier in F 3. Variable t is bound to the (  ) quantifier in F 2.

Relational Calculus EXAMPLES USING THE EXISTENTIAL (  ) QUANTIFIER: Query 1 Retrieve the name and address of all employees who work for the ‘Research’ department. Q1: {t.FNAME, t.LNAME, t.ADDRESS  EMPLOYEE(t) and (  d) (DEPARTMENT (d) and d.DNAME = “Research’ and d.DNUMBER = t.DNO)} The only free tuple variables in a relational calculus expression should be those that appear on the left of the bar (  ).

Relational Calculus EXAMPLES USING THE EXISTENTIAL (  ) QUANTIFIER: Query 1 continued: Q1: {t.FNAME, t.LNAME, t.ADDRESS  EMPLOYEE(t) and (  d) (DEPARTMENT (d) and d.DNAME = “Research’ and d.DNUMBER = t.DNO)} In Q1, t is the only free variable ; it is then bound successively to each tuple. If a tuple satisfies the conditions specified in Q1, the attributes FNAME, LNAME, and ADDRESS are retrieved for each such tuple

Relational Calculus EXAMPLES USING THE EXISTENTIAL (  ) QUANTIFIER: Query 1 continued: Q1: {t.FNAME, t.LNAME, t.ADDRESS  EMPLOYEE(t) and (  d) (DEPARTMENT (d) and d.DNAME = “Research’ and d.DNUMBER = t.DNO)} The conditions EMPLOYEE(t) and DEPARTMENT(d) specify the range relations for t and d.

Relational Calculus EXAMPLES USING THE EXISTENTIAL (  ) QUANTIFIER: Query 1 continued: Q1: {t.FNAME, t.LNAME, t.ADDRESS  EMPLOYEE(t) and (  d) (DEPARTMENT (d) and d.DNAME = “Research’ and d.DNUMBER = t.DNO)} The condition d.DNAME=‘Research’ is a selection condition and corresponds to a SELECT operation in the relational algebra,where as the condition d.DNUMBER = t.DNO is a join condition and serves a similar purpose to the JOIN operation

Relational Calculus EXAMPLES USING THE EXISTENTIAL (  ) QUANTIFIER: Query 2 For every project located in ‘Stafford’, list the project number, the controlling department number, and the department manager’s last name, birthdate, and address. Q2: {p.PNUMBER, p.DNUM, m.LNAME, m.BDATE, m.ADDRESS  PROJECT (p) and EMPLOYEE(m) and p.PLOCATION =‘Stafford’ and ((  d) (DEPARTMENT(d) and p.DNUM = d.DNUMBER and d.MGRSSN = m.SSN))}

Relational Calculus EXAMPLES USING THE EXISTENTIAL (  ) QUANTIFIER: Q2: {p.PNUMBER, p.DNUM, m.LNAME, m.BDATE, m.ADDRESS  PROJECT (p) and EMPLOYEE(m) and p.PLOCATION =‘Stafford’ and ((  d) (DEPARTMENT(d) and p.DNUM = d.DNUMBER and d.MGRSSN = m.SSN))} In Q2 there are two free tuple variables, p and m. Tuple variable d is bound to the existential quantifier.

Relational Calculus EXAMPLES USING THE EXISTENTIAL (  ) QUANTIFIER: Query 3: Make a list of project numbers for projects that involve and employee whose last name is ‘Smith’, either as a worker or a manager of the controlling department for the project. Q3: {p.PNUMBER  PROJECT(p) and (((  e)(  w) (EMPLOYEE(e) and WORKS_ON(w) and w.PNO=p.PNUMBER and e.LNAME=‘Smith’ and e.SSN=w.ESSN)) or ((  m)(  d)(EMPLOYEE(m) and DEPARTMENT(d) and p.DNUM=p.DNUMBER and d.MGRSSN=m.SSN and m.LNAME=‘Smith’)))} UNION in Relational Algebra = or in TRC

Relational Calculus EXAMPLES USING THE EXISTENTIAL (  ) QUANTIFIER: Query: Find the name of each employee who works on some project controlled by department number 5. Q(some): {e.LNAME, e.FNAME  EMPLOYEE(e) and ((  x)(  w) (PROJECT(x) and WORKS_ON(w) and x.DNUM=5 and w.ESSN=e.SSN and x.PNUMBER=w.PNO))} Q(all): {e.LNAME, e.FNAME  EMPLOYEE(e) and ((  x )(not (PROJECT(x)) or not x.DNUM=5 or ( (  w) WORKS_ON(w) and w.ESSN=e.SSN and x.PNUMBER=w.PNO))))}

Relational Calculus Using the Universal(  ) Quantifier: NOTE: Whenever we use a universal ( ) quantifier, it is quite judicious to follow a few rules to ensure that our expression make sense. Q(all): {e.LNAME, e.FNAME  EMPLOYEE(e) and ((  x )(not (PROJECT(x)) or not x.DNUM=5 or ( (  w) WORKS_ON(w) and w.ESSN=e.SSN and x.PNUMBER=w.PNO))))} We can break up this query into its basic components.

Relational Calculus Q(all): {e.LNAME, e.FNAME  EMPLOYEE(e) and ((  x )(not (PROJECT(x)) or not x.DNUM=5 or ( (  w) WORKS_ON(w) and w.ESSN=e.SSN and x.PNUMBER=w.PNO))))} We can break up this query into its basic components as follows: Q(all): {e.LNAME, e.FNAME  EMPLOYEE(e) and F’} F’= ((  x )(not (PROJECT(x)) or F 1 )) F 1 = not x.DNUM=5 or F 2 F 2 = ( (  w) WORKS_ON(w) and w.ESSN=e.SSN and x.PNUMBER=w.PNO))

Relational Calculus EMPLOYEE A i SSN.....A n PROJECT B i PNUMBER DNUM B n WORK_ON C i ESSNPNOC n

Relational Calculus Query: Find the name of each employee who works on some project controlled by department number 5. Q(some): {e.LNAME, e.FNAME  EMPLOYEE(e) and ((  x)(  w) (PROJECT(x) and WORKS_ON(w) and x.DNUM=5 and w.ESSN=e.SSN and x.PNUMBER= w.PNO))} {t   u  p(t[A] = u[A]  t[B] = u[B])}  Project Project => select certain columns (attributes) {t   x  w  p(t[A] = x[A]  t[B] = x[B] )  (t[A] = w[A]))} Employee e works on every project x in dept num 5!!!