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.

Slides:



Advertisements
Similar presentations
Chapter 6 The Relational Algebra
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Lecture 1 Relational Algebra and Relational Calculus.
The Relational Algebra
CM036: Advanced Database Lecture 3 Relational Algebra and SQL.
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
The Relational Data Model (Based on Chapter 5)
Copyright © 2004 Pearson Education, Inc.. Chapter 6 The Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
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.
1 CSE 480: Database Systems Lecture 11: SQL. 2 SQL Query SELECT FROM WHERE –In MySQL, FROM and WHERE clauses are optional –Example:
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Algebra by Pinar Senkul resources: mostly froom Elmasri, Navathe and other.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Database Management Systems. NESTING OF QUERIES  Some queries require that existing values in the database be retrieved and then used in a comparison.
Relational Algebra – Part 2
The Relational Algebra and Calculus
October 9, Announcements Exam Tuesday in class –Closed book Program 2 due Friday –Turn in using D2L dropbox –Only turn in the 4 files specified.
Relational Algebra. 2 Outline  Relational Algebra Unary Relational Operations Relational Algebra Operations from Set Theory Binary Relational Operations.
Chapter 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 6 The Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Part a The Relational Algebra and Relational Calculus Hours 1,2.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Al-Maarefa College for Science and Technology INFO 232: Database systems Chapter 3 “part 2” The Relational Algebra and Calculus Instructor Ms. Arwa Binsaleh.
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 Algebra. Slide 6- 2 Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary Relational.
Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
Announcements Today –Finish RDM (Chapter 5), begin relational algebra Reading –Sections Program 2 –Due Friday Exam –Tuesday Oct 16, in class –Closed.
Dr. Mohamed Hegazi1 The Relational Algebra and Relational Calculus.
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 11 A First Course in Database Systems.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Chapter 6 The Relational Algebra Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
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.
The Relational Algebra and Calculus
The Relational Data Model & Relational Algebra
Database Systems Chapter 6
The Relational Algebra
The Relational Algebra and Relational Calculus
The Relational Algebra and Relational Calculus
Chapter (6) The Relational Algebra and Relational Calculus Objectives
The Relational Algebra and Calculus
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
The Relational Algebra and Relational Calculus
The Relational Algebra
Introduction to Database Systems
Lecture 3 Relational Algebra and SQL
The Relational Algebra and The Relational Calculus
Presentation transcript:

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 S. This operation is used to combine tuples from two relations. The result of R(A1, A2,..., An) x S(B1, B2,..., Bm) is a relation Q with degree n + m attributes Q(A1, A2,..., An, B1, B2,..., Bm), in that order. The two operands do NOT have to be "type compatible” Example: FEMALE_EMPS  SEX=’F’ (EMPLOYEE) EMPNAMES  FNAME, LNAME, SSN (FEMALE_EMPS) EMP_DEPENDENTS  EMPNAMES X DEPENDENT

Slide 6- 2 CARTESIAN Product Example

Slide 6- 3 CARTESIAN Product Example (Cont.) EMP_DEPENDENTS  EMPNAMES X DEPENDENT

Slide 6- 4 CARTESIAN Product Example (Cont.) ACTUAL_DEPENDENTS  SSN=ESSN (EMP_DEPENDENTS) RESULT  FNAME, LNAME, DEPENDENT_NAME (ACTUAL_DEPENDENTS)

Slide 6- 5 JOIN Operation The sequence of cartesian product followed by select is used quite commonly to identify and select related tuples from two relations, a special operation, called JOIN. It is denoted by a This operation is very important for any relational database with more than a single relation, because it allows us to process relationships among relations. The general form of a join operation on two relations R(A1, A2,..., An) and S(B1, B2,..., Bm) is: R S

Slide 6- 6 JOIN Operation Example Example: Suppose that we want to retrieve the name of the manager of each department. To get the manager’s name, we need to combine each DEPARTMENT tuple with the EMPLOYEE tuple whose SSN value matches the MGRSSN value in the department tuple. We do this by using the join operation: DEPT_MGR  DEPARTMENT MGRSSN=SSN EMPLOYEE

Slide 6- 7 JOIN Operation (Cont.) A general join condition is of the form: AND AND... AND where each condition is of the form Ai  Bj, Ai is an attribute of R, Bj is an attribute of S, Ai and Bj have the same domain, and  (theta) is one of the comparison operators {, , =,  }. A JOIN operation with such a general join condition is called a THETA JOIN. Tuples whose join attributes are null do not appear in the result.

Slide 6- 8 JOIN Operation (Cont.) EQUIJOIN Operation The most common use of join involves join conditions with equality comparisons only. Such a join, where the only comparison operator used is =, is called an EQUIJOIN. In the result of an EQUIJOIN we always have one or more pairs of attributes (whose names need not be identical) that have identical values in every tuple. The JOIN seen in the previous example was EQUIJOIN. NATURAL JOIN Operation Because one of each pair of attributes with identical values is redundant, a new operation called NATURAL JOIN —denoted by *—was created to get rid of the second (redundant) attribute in an EQUIJOIN condition. The standard definition of natural join requires that the two join attributes, or each pair of corresponding join attributes, have the same name in both relations. If this is not the case, a renaming operation is applied first.

Slide 6- 9 NATURAL JOIN Operation Example (a) PROJ_DEPT  PROJECT*  (DNAME, DNUM,MGRSSN, MGRSTARTDSATE ) (DEPARTMENT)) (b) DEPT_LOCS  DEPARTMENT * DEPT_LOCATIONS

Slide Complete Set of Relational Operations The set of operations including select , project , union , set difference , and cartesian product X is called a complete set because any other relational algebra expression can be expressed by a combination of these five operations. For example: R  S = (R  S ) – ((R  S)  (S  R)) R S =  (R X S)

Slide Division Operation Examples of Division A  B A B1 B2 B3 A  B1 A  B2 A  B3 Suited for queries that include the phrase “for all”

Slide Division Example Retrieve the names (first and last) of employees who work on all the projects that ‘John Smith’ works on. First, retrieve the list of project numbers that ‘John Smith’ works on in the intermediate relation SMITH_PNOS: SMITH_PNOS   PNO (WORKS_ON ESSN=SSN (  FNAME=’John’ AND LNAME=’Smith’ (EMPLOYEE) ))

Slide Division Example (Cont.) Next, create a relation that includes tuples in the intermediate relation SSN_PNOS: SSN_PNOS   ESSN,PNO (WORKS_ON)

Slide Division Example (Cont.) Finally, apply the DIVISION operation to the two relations, which gives the desired employees’ social security numbers: SSNS(SSN)  SSN_PNOS ÷ SMITH_PNOS RESULT    FNAME, LNAME (SSNS * EMPLOYEE)

Slide Recap of Relational Algebra Operations