A First Course in Database Systems

Slides:



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

The 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.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
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.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
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.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
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.
Revision of Midterm 2 Prof. Sin-Min Lee Department of Computer Science.
Rutgers University Relational Calculus 198:541 Rutgers University.
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.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Relational Algebra Example Database Application (COMPANY) Relational Algebra –Unary Relational Operations –Relational Algebra Operations From Set Theory.
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.
CS 380 Introduction to Database Systems Chapter 7: The Relational Algebra and Relational Calculus.
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.
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 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.
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.
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.
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.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 10 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 21 A First Course in Database Systems.
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.
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.
Relational Calculus Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
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.
Jun-Ki Min.  Based on predicate calculus ◦ Predicate  a function whose value is true or false  non-procedural ◦ A relational calculus expression creates.
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.
Relational Calculus Chapter 4, Section 4.3.
Introduction to Relational Calculus Tuple Relational Calculus
Relational Algebra & Calculus
CSE202 Database Management Systems
Relational Calculus Chapter 4, Part B
The Relational Algebra and Relational Calculus
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Logics for Data and Knowledge Representation
11/22/2018.
Relational Calculus.
CS 186, Fall 2002, Lecture 8 R&G, Chapter 4
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:

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

Relational Calculus Tuple Relational Calculus Query: { t | COND (t) } where t is a tuple variable and COND(t) is a conditional expression involving t. The result of such a query is the set of all tuples t that satisfy COND( t ) .

Relational Calculus Relational Calculus Query Example: Find all employees whose salary is above $50000. { t | EMPLOYEE (t) and t.SALARY > 50000}

{ t | EMPLOYEE (t) and t.SALARY > 50000} Relational Calculus Tuple Relational Calculus (TRC) Query Example: Find all employees whose salary is above $50000. { t | EMPLOYEE (t) and t.SALARY > 50000} ==> EMPLOYEE(t) => specifies that the range relation of tuple variable t is EMPLOYEE. Each EMPLOYEE tuple t that satisfies the condition t.SALARY > 50000 will be retrieved.

Relational Calculus NOTE: t.SALARY references attribute SALARY of tuple variable t; ==> this notation resembles how attribute names are qualified with relation names or aliases in SQL. t.SALARY  t[SALARY] NOTE: This is TRC!

{ t | EMPLOYEE (t) and t.SALARY > 50000} Relational Calculus Find all employees whose salary is above $50000. { t | EMPLOYEE (t) and t.SALARY > 50000} The above query retrieves all attribute values for each selected EMPLOYEE tuple t. To retrieve only some of the attributes - say, the first and last names - we write the following: {t.FNAME, t.LNAME EMPLOYEE(t) and t.SALARY > 50000}

Relational Calculus To retrieve only some of the attributes - say, the first and last names - we write the following: {t.FNAME, t.LNAME | EMPLOYEE(t) and t.SALARY > 50000} This is equivalent to the following SQL query: SELECT T.FNAME, T.LNAME FROM EMPLOYEE AS T WHERE T.SALARY > 50000 ;

{t.FNAME, t.LNAME | EMPLOYEE(t) and t.SALARY > 50000} Relational Calculus To retrieve only some of the attributes - say, the first and last names - we write the following: {t.FNAME, t.LNAME | EMPLOYEE(t) and t.SALARY > 50000} Informally, we need to specify the following information in a TRC expression: 1. For each tuple variable t , the range relation R of t . This value is specified by a condition of the form R(t).

Relational Calculus 2. A condition to select particular combinations of tuples. As tuple variables range over their respective range relations, the condition is evaluated for every possible combination of tuples to identify the selected combinations for which the condition evaluates to TRUE. 3. A set of attributes to be retrieved, the requested attributes. The values of these attributes are retrieved for each selected combination of tuples.

Relational Calculus Take a simple SQL query query format: SELECT item 3 above (attribute list) FROM item 1 above (relation names) WHERE item 2 above (condition)

Relational Calculus Query 0 Retrieve the birthdate and address of the employee (or employees) whose name is ‘John B. Smith’. Q0: {t,BDATE, t.ADDRESS | EMPLOYEE(t) and t.FNAME = ‘John’ and t.MINIT = ‘B’ and t.LNAME = ‘Smith’}

Relational Calculus Q0: {t,BDATE, t.ADDRESS | EMPLOYEE(t) and t.FNAME = ‘John’ and t.MINIT = ‘B’ and t.LNAME = ‘Smith’} First, in TRC, we specify the requested attributes t.BDATE and t.LNAME for each selected tuple t (on left of bar!!) ( | ). Then we specify the condition for selecting a tuple following the bar (right of bar!!) ( | ) - namely, that t be a tuple of the EMLPLOYEE relation whose FNAME, MINIT, and LNAME attribute values are ‘John’, ‘B’, and ‘Smith’, respectively.

Relational Calculus Formal Syntax of TRC: {t1.A1, t2.A2, …., tn.An | COND (t1,t2, …, tn, tn+1, tn+2, …, tn+m) } where t1,t2, …, tn, tn+1, tn+2, …, tn+m are tuple variables, each Ai is an attribute of the relation on which ti ranges, and COND is a condition or formula (wff in mathematical logic) of the TRC.

Relational Calculus In another variant, called the domain relational calculus (DRC), the variables range over field values TRC has had more of an influence on SQL, while DRC has strongly influenced QBE In TRC, a tuple variable is a variable that takes on tuples of a particular relation schema as values i.e., every value assigned to a given tuple variabloe has the same number and type of fields

Relational Calculus TRC A tuple relational calculus query has the form { T | p(T)} where T is a tuple variable and p(T) denotes a formula that describes T

Relational Calculus We will shortly define formulas and queries rigorously The results of this query is the set of all tuples t for which the formula p(T) evaluates to true with T = t . The language for writing formulas p(T) is thus at the heart of TRC and is essentially a simple subset of first-order logic.

Relational Calculus Example: Find all sailors with a rating above 7. { S | S  Sailors  S.rating > 7 } When this query is evaluated on an instance of the Sailors relation, the tuple variable S is instantiated successfully with each tuple, and the test S.rating >7 is applied.

TRC Query: { S | S  Sailors  S.rating > 7 } Relational Calculus TRC Query: { S | S  Sailors  S.rating > 7 } When this query is evaluated on an instance of the Sailors relation, the tuple variable S is instantiated successfully with each tuple, and the test S.rating >7 is applied. The answer contains those instances of S that pass this test

NEXT LECTURE Relational Calculus Continued