Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.

Slides:



Advertisements
Similar presentations
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
Advertisements

The Relational Calculus
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
1 Relational Calculus Chapter 4 – Part II. 2 Formal Relational Query Languages  Two mathematical Query Languages form the basis for “real” languages.
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.
ISBN Chapter 3 Describing Syntax and Semantics.
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.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain 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.
RELATIONAL CALCULUS Prof. Sin-Min Lee Department of Computer Science.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Domains, Relations & Base RelVars (Ch
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
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.
Chapter 6 Relations. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Topics in this Chapter Tuples Relation Types Relation Values Relation.
Predicates and Quantifiers
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
Lecture 3 [Self Study] Relational Calculus
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
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.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Appendix C Overview of the QBE (Query-By-Example) Language.
Data Integrity An empty database is a correct database.
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.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Chapter 7 Relational Algebra. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.7-2 Topics in this Chapter Closure Revisited The Original Algebra:
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.
Chapter 3 Part II Describing Syntax and Semantics.
The Relational Calculus (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
IST 210 The Relational Language Todd S. Bacastow January 2004.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe The Relational Calculus The main reference of this presentation is the textbook and PPT from : Elmasri.
1 Copyright © Kyu-Young Whang Relational Calculus Chapter 4, Part B.
Copyright © Curt Hill The Relational Calculus Another way to do queries.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Semantics of Predicate Calculus For the propositional calculus, an interpretation was simply an assignment of truth values to the proposition letters of.
Relational Calculus Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Albert Gatt LIN3021 Formal Semantics Lecture 3. Aims This lecture is divided into two parts: 1. We make our first attempts at formalising the notion of.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
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.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Calculus Chapter 4, Section 4.3.
Chapter 8 Relational Calculus.
Relational Algebra & Calculus
CSE202 Database Management Systems
Formal Modeling Concepts
Relational Calculus Chapter 4, Part B
Chapter 8 Relational Calculus.
Advanced Database System
A Brief Summary for Exam 1
Relational Algebra & Calculus
Relational Calculus Chapter 4, Part B 7/1/2019.
Relational Calculus Chapter 4, Part B
Presentation transcript:

Chapter 8 Relational Calculus

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra Computational Capabilities SQL Facilities Domain Calculus Query-By-Example

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-3 Relational Calculus Based on predicate calculus, the relational calculus is a more natural language expression of the relational algebra Instead of operators used by the system to construct a result relation, the calculus offers a notation to express the result relation in terms of the source relations Relational calculus and algebra are logically equivalent

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-4 Relational Calculus Implementations Codd proposed a language called ALPHA to implement the relational calculus QUEL, an early competitor to SQL, was based on ALPHA Relational calculus came to be called tuple calculus, in distinction from domain calculus Domain calculus has been implemented by Query By Example (QBE)

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-5 Tuple Calculus - Syntax := RELATION { } | | -- “relation operator invoked” | -- “with expression” | | ( )

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-6 Tuple Calculus - Syntax Identical to the syntax of the algebra Relation operator invoked now is interpreted to mean relation definition In addition, -- “range variable definition” ::= RANGEVAR RANGES OVER ;

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-7 Tuple Calculus - WFFs s are called well-formed formulas, WFFs, or “weffs” Every reference to a range variable is either free or bound, within a context, and in particular, within a WFF

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-8 Range Variables RANGEVAR SX RANGES OVER S; RANGEVAR SY RANGES OVER S; RANGEVAR SPX RANGES OVER SP; RANGEVAR SPY RANGES OVER SP; RANGEVAR PX RANGES OVER P;

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-9 Range Variables RANGEVAR SU RANGES OVER ( SX WHERE SX.CITY = ‘London’ ) ( SX WHERE EXISTS SPX (SPX.S# = SX.S# AND SPX.P# = P# (‘P1’) ) ) ; In this example, SU ranges over the union of the set of supplier tuples for suppliers located in London, and those that supply P1

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-10 Free and Bound Variables Every reference to a range variable is either free or bound A bound reference can be replaced by a reference to some other variable without changing the meaning of the expression A free reference is not so free

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-11 Quantifiers - EXISTS EXISTS is the existential quantifier EXISTS V ( p ) -- There exists at least one value of V that makes p true Formally this is an iterated OR FALSE OR p (t1) OR … OR p (tm) -- will evaluate to false if m = 0

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-12 Quantifiers - FORALL FORALL is the universal quantifier FORALL V ( p ) -- for all values of v, p is true Formally this is an iterated AND TRUE AND p (t1) AND … AND p (tm) -- will evaluate to true as long as all are true This will evaluate to TRUE when the set is empty

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-13 Relational Operations in the calculus context is more a definition than an operator invocation ::= [WHERE ] For example: SX.S# WHERE SX.CITY = ‘London’ -- Get supplier numbers for suppliers in London

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-14 Calculus vs. Algebra Codd’s reduction algorithm reduces expressions of the calculus to algebra A language is said to be relationally complete if it is at least as powerful as the calculus And the same can be said of the algebra QUEL, based on the calculus, can be implemented by applying the algorithm to it, and then implementing the underlying algebra

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-15 SQL Facilities Because the calculus statements can be translated into algebra, they map equally well to SQL Example: Get supplier numbers for suppliers with status less than the current maximum status in the supplier table: SELECT S.S# FROM S WHERE S.STATUS < (SELECT MAX (S.STATUS) FROM S) ;

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-16 Domain Calculus Its range variables range over domains (i.e. types) instead of relations Based on checking values in the attribute domain, a bool membership condition SP { S#, S#(‘S1’), P# P#(‘P1’) } -- evaluates to true iff the shipment contains part P1 shipped by supplier S1

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-17 Query-By-Example (QBE) Language based on the domain calculus Notation which is intuitive and easy to use By making entries in blank tables, the user specifies the conditions needed in the result A condition box is used to allow more complex conditions Easy to express comparisons, uniqueness, AND and OR, and EXISTS Doesn’t express NOT EXISTS well, and so is not relationally complete