Jun-Ki Min.  Based on predicate calculus ◦ Predicate  a function whose value is true or false  non-procedural ◦ A relational calculus expression creates.

Slides:



Advertisements
Similar presentations
The Relational Calculus
Advertisements

1 Query-by-Example (QBE). 2 v A “GUI” for expressing queries. –Based on the Domain Relational Calulus (DRC)! –Actually invented before GUIs. –Very convenient.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 (Continued) The Relational Algebra and Calculus.
1 Lecture 11: Basic SQL, Integrity constraints
Database Management Systems 3ed, Online chapter, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Online Chapter Example is the school of mankind,
Relational Algebra Content based on Chapter 4 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
5/15/2015Lecture 31 CS 222 Database Management System Spring Lecture 3 Korra Sathya Babu Department of Computer Science NIT Rourkela.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Chapter 6 Example is the school of mankind, and they will learn at no.
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
Relational Algebra Relational Calculus. Relational Algebra Operators Relational algebra defines the theoretical way of manipulating table contents using.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 6- 1.
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.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Chapter 4 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Relational Algebra.  Introduction  Relational Algebra Operations  Projection and Selection  Set Operations  Joins  Division  Tuple Relational Calculus.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Relational Algebra Example Database Application (COMPANY) Relational Algebra –Unary Relational Operations –Relational Algebra Operations From Set Theory.
Relational Query Languages. Languages of DBMS  Data Definition Language DDL  define the schema and storage stored in a Data Dictionary  Data Manipulation.
Lecture 3 [Self Study] Relational Calculus
1 CS 430 Database Theory Winter 2005 Lecture 6: Relational Calculus.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Appendix C Overview of the QBE (Query-By-Example) Language.
CS 380 Introduction to Database Systems Chapter 7: The Relational Algebra and Relational Calculus.
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
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.
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.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 5 Other Relational Languages.
Advanced Relational Algebra & SQL (Part1 )
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.
1 Copyright © Kyu-Young Whang Relational Calculus Chapter 4, Part B.
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.
Lu Chaojun, SJTU 1 Extended Relational Algebra. Bag Semantics A relation (in SQL, at least) is really a bag (or multiset). –It may contain the same tuple.
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.
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.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2014.
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.
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
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Introduction to Relational Calculus Tuple Relational Calculus
CSE202 Database Management Systems
A First Course in Database Systems
Chapter # 6 The Relational Algebra and Calculus
Query-by-Example (QBE)
The Relational Algebra and Relational Calculus
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
11/22/2018.
12/5/2018.
12/31/2018.
Relational Calculus and QBE
Relational Calculus and QBE
CS 405G: Introduction to Database Systems
Presentation transcript:

Jun-Ki Min

 Based on predicate calculus ◦ Predicate  a function whose value is true or false  non-procedural ◦ A relational calculus expression creates a new relation, which is specified in terms of variables that range over rows of the stored database relations (in tuple calculus) or over columns of the stored relations (in domain calculus). ◦ In a calculus expression, there is no order of operations to specify how to retrieve the query result—a calculus expression specifies only what information the result should contain. ◦ This is the main distinguishing feature between relational algebra and relational calculus.

 The tuple relational calculus is based on specifying a number of tuple variables.  Each tuple variable usually ranges over a particular database relation, meaning that the variable may take as its value any individual tuple from that relation.  A simple tuple relational calculus query is of the form {t | COND(t)} ◦ where t is a tuple variable and COND (t) is a conditional expression involving t.  tuple variable : t  Range Expression: R(t)  R: t’s range relation ◦ The result of such a query is the set of all tuples t that satisfy COND (t).

Slide 6- 4  Example: To find the first and last names of all em ployees whose salary is above $50,000, we can writ e the following tuple calculus expression: {t.FNAME, t.LNAME | EMPLOYEE(t) AND t.SALARY>500 00}  The condition EMPLOYEE(t) specifies that the range relation of tuple variable t is EMPLOYEE.  The first and last name (PROJECTION  FNAME, LNAME ) o f each EMPLOYEE tuple t that satisfies the condition t.SALARY>50000 (SELECTION  SALARY >50000 ) will be retrieved. ◦ Qualified attribute: t.A  Tuple t’s attribute A

5  Component (con’t) ⅲ. atomic formula  Range expression: R(t) t : tuple variable R : t’s range relation  Condition: t.A θ u.B A, B : attribute θ : 비 =, ≠,,≥  Condition: t.A θ c c: constant ◦ Evaluation of atomic formula is true or false

6 ⅳ.WFF, well-formed formula  Atomic formula, boolean operator(∧,∨, ¬ ), quantifier (∀,∃) ① All atomic formulae are WFF ② if F is WFF, (F) and  F are WFF ③ if F and G are WFF, F∧G and F∨G are WFF ④ If F(f) is WFF where tuple variable t is free variable, ∀t(F(t)) and ∃t(F(t))are WFF ⑤ Expression applied above rules is WFF ◦ Example s.Sno = 100 c.Cno ≠ e.Cno s.Sno = e.Sno ∧ e.Cno ≠ c.Cno (∃e)(e.Sno = s.Sno ∧ e.Cno = 'C413')

Slide 6- 7  Two special symbols called quantifiers can appear i n formulas; these are the universal quantifier  an d the existential quantifier   Informally, a tuple variable t is bound if it is quantif ied, meaning that it appears in an  t  or  t  claus e; otherwise, it is free.  If F is a formula, then so are  t)(F) and  t)(F), wh ere t is a tuple variable. ◦ The formula  t)(F) is true if the formula F evaluates t o true for some (at least one) tuple assigned to free oc currences of t in F; otherwise  t)(F) is false. ◦ The formula  t)(F) is true if the formula F evaluates t o true for every tuple (in the universe) assigned to free occurrences of t in F; otherwise  t)(F) is false.

Slide 6- 8   is called the universal or “for all” quantifier because every tuple in “the universe of” tuple s must make F true to make the quantified for mula true.   is called the existential or “there exists” qua ntifier because any tuple that exists in “the un iverse of” tuples may make F true to make the quantified formula true.

 example ◦ {s.Sname | STUDENT(s) } ◦ {s.Sname | STUDENT(s)∧s.Dept=‘CS’ } ◦ {s.Sname, s.Dept | STUDENT(s)∧(∃e)(ENROL(e)∧ s.Sno=e.Sno∧e.Grade='A')}  In left side of bar, only free variable can be located.

Slide  Another variation of relational calculus called the domain relat ional calculus, or simply, domain calculus is equivalent to tupl e calculus and to relational algebra.  The language called QBE (Query-By-Example) that is related t o domain calculus was developed almost concurrently to SQL at IBM Research, Yorktown Heights, New York. ◦ Domain calculus was thought of as a way to explain what Q BE does.  Domain calculus differs from tuple calculus in the type of vari ables used in formulas: ◦ Rather than having variables range over tuples, the variable s range over single values from domains of attributes.  To form a relation of degree n for a query result, we must hav e n of these domain variables— one for each attribute.

Slide  An expression of the domain calculus is of th e form { x 1, x 2,..., x n | COND(x 1, x 2,..., x n, x n+1, x n+2,..., x n+m )} ◦ where x 1, x 2,..., x n, x n+1, x n+2,..., x n+m are domai n variables that range over domains (of attributes) ◦ and COND is a condition or formula of the domain r elational calculus.

12  Component ⅰ. domain variable  xSno, xSname, xDept, xYear, …  Range  Declaration of Domain variable  STUDENT(xSno, xSname, xDept, xYear)

13  Components(con’t) ⅱ. atomic formula ① Range Expression, R(x 1,x 2,…,x n ) x i : Domain variable R : x i ’s range relation Value list is a relation R’s tuple ② Condition Expression, x θ y x, y : Domain variable θ: =, ≠,,≥ ③ Condition Expression, x θ c x : domain variable c : Constant

14  Component(con’t) iii. WFF, Well-formed formula  Atomic formula, boolean operator(∧,∨, ¬ ), quantifier (∀,∃) ① All atomic formulae are WFF ② if F is WFF, (F) and  F are WFF ③ if F and G are WFF, F∧G and F∨G are WFF ④ If F(f) is WFF where tuple variable t is free variable, ∀t(F(t)) and ∃t(F(t))are WFF ⑤ Expression applied above rules is WFF

Slide ◦ example ① { xSname | STUDENT(xSno, xSname, xYear, xDept)} ② { xSname | (∃xDept) (STUDENT(xSno, xSname, xYear, xDept)∧ xDept=‘CS’) } ③ { xSno, xDept | STUDENT(xSno, xSname, xYear, xDept)∧(∃xxSno)(∃xGrade) (ENROL(xxSno, xCno, xGrade, xMidterm, xFinal)∧ xSno=xxSno∧xGrade='A‘) }  Retrieve sno and sname of a student whose final is greater than or equal to 90. ◦ {xSno,xSname | (STUDENT(xSno,xSname,xYear,xDept) ∧ (∃xFinal)(∃xxSno) (ENROL(xxSno, xCno, xGrade, xMidterm, xFinal)∧xSno=xxSno ∧ xFinal ≥ 90) }

16  QBE (Query By Example)  In 1975, Zloof with IBM  Based on domain relational calculus  Use graphic display terminal  two-dimensional syntax  Table formed “skeleton“  Example  P. (called P dot) operator (for “print”) is placed in those columns which are requested for the result of the query. ◦ example element) : domain variable STUDENT SnoSnameYearDept P._STX3

Slide  The language is very user-friendly, because it uses minimal syntax.  QBE was fully developed further with facilities for grouping, aggregation, updating etc. and i s shown to be equivalent to SQL.  The language is available under QMF (Query Management Facility) of DB2 of IBM and has b een used in various ways by other products li ke ACCESS of Microsoft, and PARADOX.

18  Simple Condition ◦ Retrieve sno and sname of students whose year = 4 and dept = ‘CS’  Duplication Elimination  'ALL’  allow duplication STUDENT SnoSnameYearDept P. 4CS STUDENT Sno SnameYearDept P.ALL4CS

19  Retrieve a table ◦ Retrieve all student  Simple way: P. in table name STUDENT SnoSnameYearDept P. STUDENT SnoSnameYearDept P.

20  Multiple condition ◦ 'OR' condition : Several rows ◦ 'AND' coondition : single row ENROL SnoCnoFinalMidterm P. C413  85 ENROL SnoCnoFinalMidterm P.C413  85

21  Multiple condition(con’t) ◦ Use condition box ENROL SnoCnoFinalMidterm P._EC_EF CONDITIONS _EC=C413 AND _EF  85

22  Retrieve with several tables  Join ◦ Retrieve name of student whose Final >= 85 or Cno = ‘C413’  Name is in STUDENT table  Sno is a join attribute ENROL SnoCnoFinalMidterm _STX _STY C413  85 STUDENT SnoSnameYearDept _STX _STY P.

23  Simple Insert ◦ Insert a tuple whose sno = 100 and cno =‘C413’ into ENROL. Note : primary key (Sno) should not be null  Insert with retrieval result ◦ Insert sno of a 4 year student into SENIOR ENROL SnoCnoGradeMidterm I.100C413 Final STUDENT SnoSnameYearDept _STX4 SENIOR Sno I._STX

24  Simple Delete ◦ Delete a tuple whose sno = 100  Delete with several table ◦ Delete student whose final < 60 in ENRON and STUDENT STUDENT SnoSnameYearDept D.100 STUDENT SnoSnameYearDept D._STX ENROL SnoCnoGradeMidterm D. _STX Final <60

25  Simple Update ◦ Update year to 2 of student whose snn = 300.  Update with arithmetic expression ◦ Increase final by 5 of student whose Cno = ‘C413’ STUDENT SnoSnameYearDept 300U.2 STUDENT SnoSnameYearDept U.3002 ENROL SnoCnoFinalMidterm U. C413 _G+5 _G