10/3/2017.

Slides:



Advertisements
Similar presentations
3/25/2017.
Advertisements

Exercise 2 Relational Calculus
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
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.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19 Algorithms for Query Processing and Optimization.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Lecture 1 Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 (Continued) The Relational Algebra and Calculus.
The Relational Algebra
LAB 4 FIGURES.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
Employee database: Conceptual Schema in ERD Chapter 3, page 62.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 7- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Copyright © 2004 Pearson Education, Inc.. Chapter 6 The Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- and EER-to-Relational Mapping.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- Mapping.
Chapter 7 Relational Database Design by ER- and EER-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- to-Relational Mapping.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- Mapping.
SQL: Schema Definition, Constraints, & Queries and Views.
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.
Query Processing and Optimization
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
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.
Al-Maarefa College for Science and Technology INFO 232: Database systems Chapter 3 “part 2” The Relational Algebra and Calculus Instructor Ms. Arwa Binsaleh.
Chapter 6 Relational Database Design by ER- and EERR-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Announcements Written Homework 1 due Nov 2 –See course web page –Exercises 5.12, 5.15, 6.17, 6.20, 6.22 (a,c,f only). Today –continue with SQL (chapter.
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 7- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution.
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 © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER- to-Relational Mapping.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus تنبيه : شرائح العرض.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Ramez Elmasri and Shamkant Navathe Lecture 8 Relational Algebra April 26, 2015.
Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
The Relational Algebra and Calculus
The Relational Algebra and Relational Calculus
The Relational Algebra and Calculus
CS580 Advanced Database Topics
Chapter # 6 The Relational Algebra and Calculus
6/22/2018.
CS4222 Principles of Database System
Company Requirements.
Session - 6 Sequence - 2 SQL: The Structured Query Language:
Introduction to Database Systems
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
SQL: Set Operations & Nested Queries. Presented by: Dr. Samir Tartir
Presentation transcript:

10/3/2017

Chapter 6 The Relational Algebra and Calculus 10/3/2017 Chapter 6 The Relational Algebra and Calculus Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Recap of Relational Algebra Operations

Database State for COMPANY All examples discussed below refer to the COMPANY database shown here.

Q4: For every project located in ‘stafford’, list the project no, the controlling depart no, and the department manager’s last name, address and birth date. STAFFORD_PROJS   Plocation=’stafford’ (project) CONTR_DEPT  (STAFFORD_PROJS DNUM= DNUMBER DEPARTMENT) PROJ_DEPT_MGR (CONTR_DEPT MGR-SSN= SSN EMPLOYEE) RESULT   PNUMBER,DNUM, LNAME, ADDRESS,BDATE (PROJ_DEPT_MGR)

Examples of in Relational Algebra Q5: Find the names of employees who work on all the projects controlled by department no 5. ADEPT5_PROJS(PNO)   PNUMBER( DNUM=’5’ PROJECT) EMP_PROJ(SSN,PNO)   ESSN,PNO(WORKS_ON) RESULT_EMP_SSNS  (EMP_PROJ ÷ DEPT5_PROJS) RESULT   LNAME, FNAME (RESULT_EMP_SSNS * EMPLOYEE)

Examples of in Relational Algebra Q7. List the names of all employee with two or more dependants Here we use the aggregate function count to count the number of employees to be more than 2 T1(ssn,no_of_dependant) ESSN ʒ Count dependant_name(DEPENDANT) T2σ NO_of_dependant >= 2 (T1) RESULTLNAME,FNAME (T2*EMPLOYEE)

Examples of in Relational Algebra Q8. List the names of managers who have at least one dependant MGRS(ssn) MGR_SSN(DEPARTMENT) EMPS_WITH_DEPS(SSN) ESSN(DEPENDANT) MGRS_WITH_DEPS (MGRS∩EMPS_WITH_DEPS) RESULTLNAME,FNAME (MGRS_WITH_DEPS*EMPLOYEE)

Examples of Queries in Relational Algebra STUDENT Course STUDENT Consider the relations student ,course, and studentCourse as follows: Course

Examples of Queries in Relational Algebra Q1. Get student names for the students who have completed course c1. Here we can make natural join because both tables have common attribute we need in join condition RESULT   S_name(Student *C_course=“c1” StudentCourse) Q2. Get student names for the students who have studied by at least book named “introduction to compilers” RESULT  s_name( s_code( c_code((σ c_book=‘introduction to compilers’(Course))* StudentCourse)) * Student)

Examples of Queries in Relational Algebra Q3. Get student names for the students who have completed all courses RESULT  s_name(( s_code,c_code(StudentCourse)÷  C_code(course))*(student) Q4. Get student codes for the students who have completed at least all those courses completed by student s2 RESULT  s_code( s_code,c_code(studentCourse)÷  c_code(σ s_code=‘s2’(studentCourse)))

Examples of Queries in Relational Algebra Q5. Get student names for the students who have not completed course c2 Here we firstly get students who have completed the course c2 and make the difference between the result and all student in student realtion RESULT  s_name(( s_code (Student) –  s_code (σ c_code=‘c2’(StudentCourse)))* Student) Q6. get all pairs of student names such that the two students are in the same year. Here we take acopy from table student and rename it as stud1 And then we make join between both relaions RESULT stud1.s_name,stud1.s_code( σ((stud1.s_Code=student.s_code)&(stud1.s_year=student.s_year)) (ρ stud1(student)) * (student))