Exercise 2 Relational Calculus

Slides:



Advertisements
Similar presentations
Chapter 6 The Relational Algebra
Advertisements

Week 5 Relational Database Design by ER- -to-Relational Mapping.
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
The Relational Algebra
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.
Defined by Edgar Codd in 1970 Defined by Edgar Codd in 1970 Considered ingenious but impractical Considered ingenious but impractical Conceptually simple.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
COMPANY schema EMPLOYEE
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
Lecture 1 Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 (Continued) The Relational Algebra and Calculus.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
The Relational Algebra
Database technology Lecture 2: Relational databases and SQL
Dept. of Computer & Information Sciences
FEN More about SELECT, Nested selects GROUP BY, HAVING, ORDER BY Other joins Aggregate functions Views More about SQL.
LAB 4 FIGURES.
Exercise 1 Relational Algebra Database System-dww.
Exploring Microsoft Access 2003 Chapter 4 Proficiency: Relational Databases, External Data, Charts, Pivot, and the Switchboard.
Employee database: Conceptual Schema in ERD Chapter 3, page 62.
- relation schema, relations - database schema, database state
Review Database Application Development Access Database Development ER-diagram Forms Reports Queries.
Jyh-haw Yeh Dept. of Computer Science Boise State University
Relational Data Model Sept. 2014Yangjun Chen ACS Outline: Relational Data Model Relational Data Model -relation schema, relations -database schema,
관계 연산자 & SQL. Selection SELECT * FROM r WHERE A=B AND D>5.
FEN  Queries: SELECT  Data Manipulation: INSERT, UPDATE, DELETE SQL: Structured Query Language – Part 2.
Review: Application of Database Systems
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- Mapping.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
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.
Retrieve the names of all employees in department 5 who work more than 10 hours per week on the ‘ProductX’ project. p10ssn ← (Π essn (σ hours > 10 (works-on.
 Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate) 
Database Management Systems. NESTING OF QUERIES  Some queries require that existing values in the database be retrieved and then used in a comparison.
The Relational Algebra and Calculus
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
Structured Query Language
Slide 6- 1 Additional Relational Operations Aggregate Functions and Grouping A type of request that cannot be expressed in the basic relational algebra.
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.
1Fundamentals of Database Systems 기본키에 밑줄을 그은 COMPANY 관계 데이타베이스 스키마 FNAMEMINITLNAMESSNBDATEADDRESSSEXSALARYSUPERSSNDNO EMPLOYEE DNAMEDNUMBERMGRSSNMGRSTARTDATE.
Mapping ER Diagrams to Tables
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 تنبيه : شرائح العرض.
CS580 Advanced Database Topics Chapter 8 SQL Irena Pevac.
The SQL Database Grammar
CS580 Advanced Database Topics
Chapter 4 Basic SQL.
6/22/2018.
Database Design The Relational Model Text Ch5
Relational Database Design by ER- and EER-to-Relational Mapping
Relational Database Design by ER-to-Relational Mapping
Mapping ER Diagrams to Tables
Outline: Relational Data Model
Joining Tables ضم الجداول وإستخراج مناظر views منها الهدف : 1- استخراج المعلومات من جدولين أو اكثر بالإستفادة من الرابط بينهما وبإستخدام SQL 2- شروط قواعد.
Company Requirements.
Relational Algebra Sample Questions.
Relational Database Design by ER- and EER-to-Relational Mapping
Review: Application of Database Systems
1. Explain the following concepts: (a) superkey (b) key
1.(5) Describe the working process with a database system.
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
1. Explain the following concepts of the ER data model:
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
SQL: Set Operations & Nested Queries. Presented by: Dr. Samir Tartir
Answers to Midterm - Exam. Feb. 28, 2018
Answers to Midterm - Exam. Feb. 27, 2006
Presentation transcript:

Exercise 2 Relational Calculus Database System-dww

6 Relations of Company Database System-dww

FNAME,LNAME(SALARY>‘50000’ (EMPLOYEES)) Find the first and last names of all employees whose salary is above $50,000 Rel Algebra  FNAME,LNAME(SALARY>‘50000’ (EMPLOYEES)) Tuple Rel Calculus  {t.FNAME,t.LNAME|EMPLOYEE(x) AND t.SALARY>‘50000’)) Domain Rel Calculus  {ac|(Ǝi) EMPLOYEE(abcdefghijkl) AND i>‘50000’)) SQL  select FNAME, LNAME from EMPLOYEES where SALARY>‘50000’ Database System-dww

Exercises (a) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project. (b) List the names of employees who have a dependent with the same first name as themselves. (c) Find the names of employees that are directly supervised by 'Franklin Wong'.  (e) Retrieve the names of employees who work on every project. Database System-dww

Exercises (f) Retrieve the names of employees who do not work on any project. (i) Find the names and addresses of employees who work on at least one project located in Houston but whose department has no location in Houston. (j)List the last names of department managers who have no dependents. Database System-dww

P W E WORKS_ON_ProductX (Rel.A) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project Graphical approach can be used to help the logical and prosedural approach Example of above query, the graphical approach: clue from query the relations that (may) work on the query are in the red text P Pnumber=Pno W ESSN=SSN E Fname, Lname (?) Pname=‘ProductX’ Hours > 10 Dno = 5 ProductX > 10 5 WORKS_ON_ProductX (Rel.A) (PNAME=‘ProductX’(PROJECT) PNUMBER=PNO(WORKS_ON)) EMPLOYEE_DEPT5_WORKS_MORE_10_onProductX (Rel.B) ((EMPLOYEE) SSN=ESSN( HOURS>10(Rel.A))) RESULT  FNAME,LNAME(DNO=‘5’ (Rel.B)) Database System-dww

P W E { e.LNAME, e.FNAME | EMPLOYEE(e) AND e.DNO=5 AND (Ǝp)(Ǝw) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project P Pnumber=Pno W ESSN=SSN E Fname, Lname (?) Pname=‘ProductX’ Hours > 10 Dno = 5 ProductX > 10 5 { e.LNAME, e.FNAME | EMPLOYEE(e) AND e.DNO=5 AND (Ǝp)(Ǝw) (WORKS_ON(w) AND PROJECT(p) AND e.SSN=w.ESSN AND w.PNO=p.PNUMBER AND p.PNAME='ProductX' AND w.HOURS>10 ) } { qs | EMPLOYEE(qrstuvwxyz) AND z=5 AND (Ǝa) (Ǝb) (Ǝe) (Ǝf) (Ǝg) ( WORKS_ON(efg) AND PROJECT(abcd) AND t=e AND f=b AND a='ProductX' AND g>10 ) } Database System-dww

List the names of employees who have a dependent with the same first name as themselves. Dp Depend_name=Fname E Fname, Lname (?) ESSN=SSN RESULT  FNAME,LNAME(DEPENDENT (ESSN,DEPEND_NAME)=(SSN,FNAME)(EMPLOYEE)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND (Ǝd) ( DEPENDENT(d) AND e.SSN=d.ESSN AND e.FNAME=d.DEPENDENT_NAME ) } { qs | (Ǝt) (Ǝa) (Ǝb) ( EMPLOYEE(qrstuvwxyz) AND DEPENDENT(abcde) AND a=t AND b=q ) } Database System-dww

Find the names of employees that are directly supervised by 'Franklin Wong'. E_SSN_FRANKLIN_WONG(Rel.A) ( SSN( FNAME=‘FRANKLIN’ LNAME=‘WONG’(EMPLOYEE))) E_SUPERVISED_BY_FRANKLIN_WONG (Result) ( FNAME, LNAMES(EMPLOYEE) SUPERSSN=SSN(Rel.A)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND (Ǝs) ( EMPLOYEE(s) AND s.FNAME='Franklin' AND s.LNAME='Wong' AND e.SUPERSSN=s.SSN ) } { qs | (Ǝy) (Ǝa) (Ǝc) (Ǝd) ( EMPLOYEE(qrstuvwxyz) AND EMPLOYEE(abcdefghij) AND a='Franklin' AND c='Wong' AND y=d ) } Database System-dww

Retrieve the names of employees who work on every project ALL_EMPLOYEE(SSN, PNO)(Rel.A) ( SSN, PNO(WORKS_ON)) ALL_PROJECT(PNO)(Rel.B) ( PNO(PROJECT)) E_ALL_PROJECT ( Rel.A÷Rel.B) RESULT ( FNAME, LNAME (E_ALL_PROJECT * EMPLOYEE)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND (Ѵp) ( NOT(PROJECT(p)) OR (Ǝw) (WORKS_ON(w) AND p.PNUMBER=w.PNO AND w.ESSN=e.SSN ) ) } { qs | (Ǝt) ( EMPLOYEE(qrstuvwxyz) AND (Ѵb) ( NOT(PROJECT(abcd)) OR (Ǝe) (Ǝf) (WORKS_ON(efg) AND e=t AND f=b) ) } Database System-dww

Retrieve the names of employees who do not work on any project ALL_EMPLOYEE(SSN)(Rel.A) ( SSN(EMPLOYEE)) ALL_EMPLOYEE_WORKING(SSN)(Rel.B) ( ESSN(WORKS_ON)) E_NOT_WORKING ( Rel.A - Rel.B) RESULT ( FNAME, LNAME ( (EMPLOYEE) SSN=ESSN(E_NOT_WORKING)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND NOT(Ǝw) ( WORKS_ON(w) AND w.ESSN=e.SSN ) } { qs | (Ǝt) ( EMPLOYEE(qrstuvwxyz) AND NOT(Ǝa) (WORKS_ON(abc) AND a=t ))} Database System-dww

{ e.LNAME, e.FNAME, e.ADDRESS | EMPLOYEE(e) AND (Ǝp) (Ǝw) Find the names and addresses of employees who work on at least one project located in Houston but whose department has no location in Houston { e.LNAME, e.FNAME, e.ADDRESS | EMPLOYEE(e) AND (Ǝp) (Ǝw) (WORKS_ON(w) AND PROJECT(p) AND e.SSN=w.ESSN AND w.PNO=p.PNUMBER AND p.PLOCATION='Houston' AND NOT(Ǝl) ( DEPT_LOCATIONS(l) AND e.DNO=l.DNUMBER AND l.DLOCATION='Houston' ) ) } { qsv | (Ǝt) (Ǝz) ( EMPLOYEE(qrstuvwxyz) AND (Ǝb) (Ǝc) (Ǝe) (Ǝf) ( WORKS_ON(efg) AND PROJECT(abcd) AND t=e AND f=b AND c='Houston' AND NOT(Ǝh) NOT(Ǝi) ( DEPT_LOCATIONS(hi) AND z=h AND i='Houston’ ) ) } Database System-dww

List the last names of department managers who have no dependents D_MNG_SSN(Rel.A)( SSN(DEPARTMENT) E_WITH_DEPENDENT(Rel.A)( SSN(DPENDENT) MNGR_NO_DEPENDENT(Rel.A – Rel.B) RESULT( LNAME(EMPLOYEE * MNGR_NO_DEPENDENT)) { e.LNAME | EMPLOYEE(e) AND (Ǝd) ( DEPARTMENT(d) AND e.SSN=d.MGRSSN AND NOT(Ǝx) (DEPENDENT(x) AND e.SSN=x.ESSN) ) } { s | (Ǝt) ( EMPLOYEE(qrstuvwxyz) AND (Ǝc) ( DEPARTMENT(abcd) AND t=c AND NOT(Ǝe) (DEPENDENT(efghi) AND e=t) ) } Database System-dww