Copyright © 2003-2008 Curt Hill The Relational Calculus Another way to do queries.

Slides:



Advertisements
Similar presentations
Relational Algebra Chapter 4, Part A
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
The Relational Calculus
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
D ATABASE S YSTEMS I R ELATIONAL A LGEBRA. 22 R ELATIONAL Q UERY L ANGUAGES Query languages (QL): Allow manipulation and retrieval of data from a database.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Database Management System Module 3:. Complex Constraints In this we specify complex integrity constraints included in SQL. It relates to integrity constraints.
1 Relational Calculus Chapter 4 – Part II. 2 Formal Relational Query Languages  Two mathematical Query Languages form the basis for “real” languages.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4.
Relational Algebra Content based on Chapter 4 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
R ELATIONAL A LGEBRA M ORE POINTERS FROM T UESDAY.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
1 Lecture 5: Relational calculus
Relational Calculus CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth   We will occasionally use this arrow notation unless there is danger of.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Relational Calculus R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion. Ronald Graham Elements of Ramsey.
Introduction to Database Systems 1 Relational Calculus Relational Model : Topic 2.
Relational Calculus CS 186, Fall 2003, Lecture 6 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
Rutgers University Relational Calculus 198:541 Rutgers University.
1 Announcements Read 6.7 – 6.10 for Friday Homework 6, due Friday 10/29 Research paper –List of sources - due 10/29 Department Seminar –The Role of Experimentation.
Relational Algebra.  Introduction  Relational Algebra Operations  Projection and Selection  Set Operations  Joins  Division  Tuple Relational Calculus.
DEDUCTIVE DATABASE.
Review “Query Languages” Algebra, Calculus, and SQL.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Copyright © Curt Hill The Relational Algebra What operations can be done?
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.
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.
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
Relational Calculus. Non Procedural or Declarative Calculus has variables, constants, comparison ops, logical connectives and quantifiers. There are TWO.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Lecture#6: Relational calculus.
Relational Calculus R&G, Chapter 4. Relational Calculus Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). Calculus.
Relational Calculus CS 186, Spring 2005, Lecture 9 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
Relational Algebra.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
IST 210 The Relational Language Todd S. Bacastow January 2004.
Copyright 2003 Curt Hill Queries in SQL Syntax and semantics.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
1 Copyright © Kyu-Young Whang Relational Calculus Chapter 4, Part B.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Relational Calculus Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
1 Relational Algebra. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational model supports.
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
A First Course in Database Systems
Relational Calculus Chapter 4, Part B
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Logics for Data and Knowledge Representation
Relational Calculus.
CS 186, Fall 2002, Lecture 8 R&G, Chapter 4
Chapter 6: Formal Relational Query Languages
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Relational Algebra & Calculus
Relational Calculus Chapter 4, Part B 7/1/2019.
Relational Calculus Chapter 4 – Part II.
Relational Calculus Chapter 4, Part B
Presentation transcript:

Copyright © Curt Hill The Relational Calculus Another way to do queries

Copyright © Curt Hill Calculus Declarative way to form a query Two types –Tuple Relational Calculus –Domain Relational Calculus Subsets of first order logic Formulas are the main unit –Used to construct the tables that satisfy the query

Copyright © Curt Hill Formulas Operators Quantifiers Constants Comparisons All tuples that makes the formula true are in the answer table

Copyright © Curt Hill TRC and DRC Tuple Relational Calculus considers a tuple as variable Domain Relational Calculus considers a Domain a variable –A domain is math for the field or attribute values

Copyright © Curt Hill Atomic Formulas A simple statement connecting a tuple or domain to some data We may compare any tuple value or domain value with constants Since tables are sets they are expressed as set expressions: –{C|C  Courses} –The set of all tuples C such that C is an element of the Courses relation You may also compare a tuple element with a value

Copyright © Curt Hill Formulas Atomic formulas need to be combined to be useful They are combined with AND (  ) OR (  ) and modified with NOT (  ) {C|C  Courses  C.dept=CS} –This should be easy to convert into a relational algebra selection –This is declarative not procedural

Copyright © Curt Hill Query By Example QBE is a graphical way to specify this {C|C  Courses  C.dept=CS} Click a table to indicater Fill in the desired values DeptNumberCrhrTitle CS

Copyright © Curt Hill Quantifiers Two common quantifiers –There exists  T(predicate(T)) –For all  T(predicate(T)) These bind a formula to a variable This variable may then be used in a larger formula  Courses(Courses.number>299) –True if there is one course that is so numbered

Copyright © Curt Hill Quantified queries Any student taking any upper level course {S | S  Students   G  Grades (G.number>299  S.naid=G.naid)} Any student taking only upper level courses {S | S  Students   G  Grades (G.number>299  S.naid=G.naid)}

Copyright © Curt Hill Unsafe queries Any query with an infinite number of answers –Legal syntax, illegal results {C|  C  Courses} This possibility is not present in the algebra –The algebra always deals with finite relations

Copyright © Curt Hill Equivalence and completeness Every series of relational algebra expressions may be expressed as a safe calculus formula Every safe calculus formula may be expressed as a series of relational algebra operations –A must for implementation Any language that can express any relational algebra expression is said to be relationally complete –SQL is relationally complete

Copyright © Curt Hill Domain Relational Calculus Most of the previous examples were of the Tuple Relational Calculus In the DRC we show the construction of the tuple using domain values or only show the domain values Different syntax, but equivalent

Domain Relational Constructions In the DRC we construct tuples from fields –Not rely on them as variables Then we determine the values we want these fields to have The notation for this construction is: where the fs are fields Copyright © Curt Hill

DRC Example Consider this formula { | m>299   d, m, x, n (  Grades)   n, a, r(  Students) } This says construct a table of tuples –Two elements in each tuple, a and m Student name is a, naid is n –There must exist a grade tuple and a student tuple with these characteristics Same naid and course number > 299 Copyright © Curt Hill

DRC and TRC example In TRC we might say: {S | S  Students   G  Grades (G.number>299  S.naid=G.naid)} This gives approximately the same table as the previous except there are more fields in each row The DRC makes it easy to construct tuples that do not exist in any table

Copyright © Curt Hill Queries using relational calculus Consider the college schema tables: –Course –Students –Grade –Faculty –Faculty_teach –Department –Division

Copyright © Curt Hill Find student grades DRC { |  sc(  Grades)   name(  Students)} TRC {T|  T2  Grades  T.naid = T2.naid   T3  Students  T3.naid = T.naid  T.addr = T3.addr  T.dp = T2.dp  T.cr = T2.cr  T.sc = T2.sc}

Copyright © Curt Hill Find all the courses taught by faculty members (include credit hours) { |  naid,dp,dg,ar,title(  Faculty)   Course   Faculty_Teach )} Implied equality in naid, dept, number, crhr

Copyright © Curt Hill Access Choose Tables

Copyright © Curt Hill Access Choose Fields

Copyright © Curt Hill Some others Find the departmental chairs for each faculty member Find all the students who got a B or better in any CS class Find all the students that each faculty member has Find all the students who got an A in Calculus and an A in CIS 385