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.

Slides:



Advertisements
Similar presentations
Chapter 6 The Relational Algebra
Advertisements

The Relational Calculus
Database System - Assignment #3 Sept. 2012Yangjun Chen ACS Assignment #3 due Wed., Nov. 14, (30) Exercise 7.17 on Page 235 Show the result.
Lecture 1 Relational Algebra and Relational Calculus.
The Relational Algebra
Relational Algebra.
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 6- 1.
Operations in the Relational Model These operation can be expressed in an algebra, called “relational algebra”. In this algebra relations are the operands.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
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.
The Relational Algebra and Calculus. Relational Algebra Overview Relational algebra is the basic set of operations for the relational model These operations.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
Relational Algebra Example Database Application (COMPANY) Relational Algebra –Unary Relational Operations –Relational Algebra Operations From Set Theory.
Relational Algebra - Chapter (7th ed )
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
CS 380 Introduction to Database Systems Chapter 7: The Relational Algebra and Relational Calculus.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Algebra by Pinar Senkul resources: mostly froom Elmasri, Navathe and other.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
The Relational Algebra and Calculus
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 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Slide 6- 1 CARTESIAN (or cross) Product Operation Defines a relation Q that is the concatenation of every tuple of relation R with every tuple of relation.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 6 The Relational Algebra.
Al-Maarefa College for Science and Technology INFO 232: Database systems Chapter 3 “part 2” The Relational Algebra and Calculus Instructor Ms. Arwa Binsaleh.
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.
The Relational Algebra. Slide 6- 2 Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary Relational.
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.
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 9 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 6 The Relational Algebra Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 20 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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus تنبيه : شرائح العرض.
Relational Algebra National University of Computer and Emerging Sciences Lecture # 6 June 30,2012.
Database Systems 主講人 : 陳建源 日期 :99/11/30 研究室 : 法 Chapter 6 The Relational Algebra.
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
The Relational Algebra and Relational Calculus
Chapter (6) The Relational Algebra and Relational Calculus Objectives
The Relational Algebra and Calculus
A First Course in Database Systems
Fundamental of Database Systems
The Relational Algebra and Relational Calculus
Chapter 6: Relational Algebra Fall 2015 Dr. Abdullah Almutairi
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
Chapter 4 The Relational Algebra and Calculus
CS4222 Principles of Database System
The Relational Algebra and Calculus
11/22/2018.
12/5/2018.
12/31/2018.
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 11 A First Course in Database Systems

Relational Algebra Chapter 5 SELECTION  : Movie title yearlength inColor studioName producerC# Star Wars yes Fox Mighty Duck yes Disney Suppose we want the Set of tuples in the relation Movie(title, year, length, inColor, studioName, producerC#) that represent Fox movies at least 100 minutes long.  c (R) =  length  100 AND studioName = ‘Fox’ (Movie)

Relational Algebra  c (R) =  length  100 AND studioName = ‘Fox’ (Movie) ==> Result title yearlengthinColorstudioNameproducerC# Star Wars YesFox12345

Relational Algebra Chapter 5 PROJECTION  :  Attribute list (R) Movie titleyearlength inColor studioName producerC# Star Wars yes Fox Mighty Duck yes Disney Wayne’s W yes Paramount  title, year, length (Movie)

Relational Algebra Chapter 5 PROJECTION  :  title, year, length (Movie) Movie titleyearlength Star Wars Mighty Duck Wayne’s W

Relational Algebra Chapter 5 SET THEORETIC OPERATIONS: Retrieve SSN of all employees who either work in DEP5 or directly supervise an employee who works in DEP5. Solution: Use union operation on Result1 and Result2 DEP5_EMPS   DNO = 5 (EMPLOYEE) RESULT1   SSN (DEP5_EMPS ) RESULT2(SSN)   SUPPERSSN (DEP5_EMPS ) RESULT  RESULT1  RESULT2

Relational Algebra QUERY RESULT: RESULT1SSN RESULT2SSN RESULTSSN Query result after the UNION operation: RESULT1  RESULT2

Relational Algebra Set Theoretic Operations: UNION, INTERSECTION, and SET DIFFERENCE ==> These operations are adapted to relational databases where the two relations on which they apply must have the same types of tuples; ==> UNION compatible

Relational Algebra Chapter 5 Set Theoretic Operations: R(A 1, A 2, …., A n ) and S(B 1, B 2, …, B n ) is UNION compatible if dom(A i ) = dom(B i ) for 1  i  n. ==> two relations have the same number of attributes and that each pair of corresponding attributes have the same domain.

Relational Algebra Chapter 5 JOIN Operation: EMP_DEPENDENTS  EMPNAMES  DEPENDENT ACTUAL_DEPENDENTS   ssn = essn (EMP_DEPENDENTS) replaced with single JOIN operation: ACTUAL_DEPENDENTS  EMPNAMES  SSN = ESSN DEPENDENT

Relational Algebra Chapter 5 Examples of Queries in Relational Algebra: Query 1 Retrieve the name and address of all employees who work for the ‘Research’ department. RESEARCH_DEPT   DNAME = ‘RESEARCH’ (DEPARTMENT) RESEARCH_EMP  (RESEARCH_DEPT  DNUMBER = DNO EMPLOYEE) RESULT  FNAME, LNAME, ADDRESS (RESEARCH_EMPS)

Relational Algebra Chapter 5 Examples of Queries in Relational Algebra: Query 2 For every project located in ‘Stafford’, list the project number, the controlling department number, and the department manager’s last name, address, and birthdate. STAFFORD_PROJS   PLOCATION = ‘Stafford’ (DEPARTMENT) CONTR_DEPT  (STAFFORD_PROJS  DNUM = DNUMBER DEPARTMENT) PROJ_DEPT_MGR  (CONTR_DEPT  MGRSSN = SSN EMPLOYEE) RESULT  PNUMBER, DNUM, LNAME, ADDRESS, BDATE (PROJ_DEPT_MGR)

Relational Algebra Chapter 5 Relational Calculus: Relational calculus is a formal query language where we write on declarative expression to specify a retrieval request and hence there is no description of how to evaluate a query!! A calculus expression specifies WHAT is to be retrieved rather than HOW to retrieve it. Declarative Language Procedural Language

Relational Algebra Chapter 5 Relational Calculus: ==> nonprocedural language (Declarative Language) Relational Algebra: ==> Procedural Language

Relational Algebra Chapter 5 Relational Algebra ==> Procedural where we must write a sequence of operations to specify a retrieval request (HOW process). Relational Calculus ==> Declarative we express WHAT is to be retrieved without specifying HOW to retrieve it.

Relational Algebra Chapter 5 Expressive Power of the Two Languages: Any retrieval that can be specified in relational algebra can also be specified in the relational calculus, and vice versa => expressive power of two languages is identical

Relational Algebra Expressive Power of the Two Languages: Any retrieval that can be specified in relational algebra can also be specified in the relational calculus, and vice versa => expressive power of two languages is identical ==> led to the definition of the concept of relationally complete language.

Relational Algebra Complete Set of Relational Algebra Operations: All the operations discussed so far can be described as a sequence of only the operations SELECT, PROJECT, UNION, SET, DIFFERENCE, and CARTESIAN PRODUCT. Hence, the set { , , , -,  } is called a complete set of relational algebra operations.

Relational Calculus A relational query language L is considered relationally complete if we can express in L any query that can be expressed in relational calculus. Relational completeness has become an important basis for comparing the expressive power of high- level query languages.

Relational Calculus Tuple Variables and Range Relations 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.

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 $ { t | EMPLOYEE (t) and t.SALARY > 50000}

Relational Calculus Relational Calculus Query Example: Find all employees whose salary is above $ { 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 > 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]

Relational Calculus NEXT LECTURE Relational Calculus