{ PreviousEducation ( CollegeName, StartDate, EndDate, { Degree (DegreeName, Month, Year) }, { Transcript (CourseName, Semester, Year, Grade) } ) }



Similar documents
CSC 443 Data Base Management Systems. Basic SQL

Relational Schema. CS 4700/6700 A Sample of Small Database Design Using Microsoft Access

Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views

CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES

New York University Computer Science Department Courant Institute of Mathematical Sciences

ER & EER to Relational Mapping. Chapter 9 1

Introduction to SQL: Data Retrieving

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Lab Assignment Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying over the database with SQL

SQL Nested & Complex Queries. CS 377: Database Systems

CHAPTER 3: DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

Part 4: Database Language - SQL

Lab Manual. Database Systems COT-313 & Database Management Systems Lab IT-216

Summary on Chapter 4 Basic SQL

Exercise 1: Relational Model

SQL-99: Schema Definition, Basic Constraints, and Queries

CSC 443 Fall 2011 Dr. R. M. Siegfried. Answers to Assignment #1

CIS 631 Database Management Systems Sample Final Exam

10CS54: DATABASE MANAGEMENT SYSTEM

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

CS 338 Join, Aggregate and Group SQL Queries

New York University Computer Science Department Courant Institute of Mathematical Sciences

How To Create A Table In Sql (Ahem)

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25)

The Relational Algebra

Lecture 6. SQL, Logical DB Design

CPS352 Database Systems: Design Project

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

The Relational Data Model and Relational Database Constraints

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Review: Participation Constraints

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

1. SELECT DISTINCT f.fname FROM Faculty f, Class c WHERE f.fid = c.fid AND c.room = LWSN1106

More SQL: Assertions, Views, and Programming Techniques

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Chapter 9, More SQL: Assertions, Views, and Programming Techniques

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

b. Examine the following histories. Draw their serialization graph and identify which of them is serializable given reasons.

Figure 14.1 Simplified version of the

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Databases in Engineering / Lab-1 (MS-Access/SQL)

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

SQL NULL s, Constraints, Triggers

Introduction to SQL ( )

3. Relational Model and Relational Algebra

Introduction to normalization. Introduction to normalization

Data Modeling. Database Systems: The Complete Book Ch ,

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

Database Design and the E-R Model

Databases What the Specification Says

IT2305 Database Systems I (Compulsory)

How To Use The Database In Jdbc.Com On A Microsoft Gdbdns.Com (Amd64) On A Pcode (Amd32) On An Ubuntu (Amd66) On Microsoft

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Structured Query Language (SQL)

The Entity-Relationship Model

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Information Systems SQL. Nikolaj Popov

Introduction to SQL C H A P T E R3. Exercises

EECS 647: Introduction to Database Systems

COURSE CODE: CIT 844 COURSE TITLE: ADVANCED DATABASE MANAGEMENT SYSTEM

VIEWS virtual relation data duplication consistency problems

There are five fields or columns, with names and types as shown above.

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

IT2304: Database Systems 1 (DBS 1)

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

CHAPTER 3. Relational Database Management System: Oracle. 3.1 COMPANY Database

Answer Key. UNIVERSITY OF CALIFORNIA College of Engineering Department of EECS, Computer Science Division

Introduction to Microsoft Jet SQL

Fundamentals of Database Systems. Laboratory Manual 1. Rajshekhar Sunderraman. Georgia State University. August 2010

Entity-Relationship Model

Requirement Analysis & Conceptual Database Design. Problem analysis Entity Relationship notation Integrity constraints Generalization

DATABASE NORMALIZATION

Database Design--from E-R Diagram to SQL Statement

4. SQL. Contents. Example Database. CUSTOMERS(FName, LName, CAddress, Account) PRODUCTS(Prodname, Category) SUPPLIERS(SName, SAddress, Chain)

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Data Modeling: Part 1. Entity Relationship (ER) Model

CSCI-GA Database Systems Lecture 7: Schema Refinement and Normalization

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

featuring data privacy Andres Avelino Campos Sainz A Project submitted in partial fulfillment of the requirements for the degree of

CMU - SCS / Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

Databases and BigData

Chapter 6: Integrity Constraints

Scheme G. Sample Test Paper-I

Database Management Systems. Chapter 1

CMPT 354 Database Systems. Simon Fraser University Summer Instructor: Oliver Schulte

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Define terms Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins

Relational Algebra. Module 3, Lecture 1. Database Management Systems, R. Ramakrishnan 1

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Chapter 10. Functional Dependencies and Normalization for Relational Databases

University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao

Chapter 3. Data Modeling Using the Entity-Relationship (ER) Model

Chapter 10 Functional Dependencies and Normalization for Relational Databases

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Database Design Methodologies

Boats bid bname color 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red. Figure 1: Instances of Sailors, Boats and Reserves

Transcription:

Tutorial 3 Solution Exercise1: Exercise 2: { PreviousEducation ( CollegeName, StartDate, EndDate, { Degree (DegreeName, Month, Year) }, { Transcript (CourseName, Semester, Year, Grade) } ) } Exercise 3: (a) Entity types: BANK, ACCOUNT, CUSTOMER, LOAN (b) Weak entity type: BANK-BRANCH. Partial key: BranchNo. Identifying relationship: BRANCHES. (c) The partial key BranchNo in BANK-BRANCH specifies that the same BranchNo value may occur under different BANKs. The identifying relationship BRANCHES specifies that BranchNo values are uniquely assigned for those BANK-BRANCH entities that are related to the same BANK entity. Hence, the combination of BANK Code and BranchNo together constitute a full identifier for a BANK-BRANCH.

(d) Relationship Types: BRANCHES, ACCTS, LOANS, A-C, L-C. The (min, max) constraints are shown below. (e) The requirements may be stated as follows: Each BANK has a unique Code, as well as a Name and Address. Each BANK is related to one or more BANK-BRANCHes, and the BranhNo is unique among each set of BANK-BRANCHes that are related to the same BANK. Each BANK-BRANCH has an Address. Each BANK-BRANCH has zero or more LOANS and zero or more ACCTS. Each ACCOUNT has an AcctNo (unique), Balance, and Type and is related to exactly one BANK-BRANCH and to at least one CUSTOMER. Each LOAN has a LoanNo (unique), Amount, and Type and is related to exactly one BANK-BRANCH and to at least one CUSTOMER. Each CUSTOMER has an SSN (unique), Name, Phone, and Address, and is related to zero or more ACCOUNTs and to zero or more LOANs. (f) The (min, max) constraints would be changed as follows:

Mid 1 Solution: Question 1 : DBMS enables users to create and maintain a database. A foreign key is a referential constraint between two tables. It identifies a column or a set of columns in one table that refers to a set of columns in another table. Referential integrity constraint is specified between two relations and is used to maintain the consistency among tuples in the two relations. Question 2 : The schema is: Person(ssn, name, address) Car(license, state, model, make, year, owner) Car.owner foreign key to Person.ssn Claim(claimId, description, policy) ** Note: This is for 3-way relationship version. For weak entity version, Item.date is also a key field. Item(ssn, license, state, claimid, date, amount)

Item.ssn foreign key to Person.ssn Item.claim foreign key to Claim.claimId Item.license and Item.state foreign key to Car.license and Car.state Payment(claimId, date, ssn, amount) Payment.ssn foreign key to Person.ssn Payment.claimId foreign key to Claim.claimId Note the primary key of payment depends on your assumptions. You could make it have an auto-number or some other system generated id in which case it is: Payment(id, ssn, claimid, date, amount) You could make Payment a weak entity dependent on claim id and use id or date as PPK: Payment(id, ssn, claimid, date, amount) OR Payment(ssn, claimid, date, amount) In all cases, there still is a foreign key on ssn and on claimid. Question 3: 1. What are the names of students enrolled in CS380? name( csc380=code(student enrolledin)) 2. Which subjects is Yazeed taking? code( name=yazeed(student enrolledin)) 3. Who teaches CSC 380? lecturer( code=csc380(subject)) 4. What are the names of students in both CSC 380 and CSC 383? name( code=csc380(student enrolledin)) name( code=csc383(student enrolledin))

CSC 380 Introduction to Database Solution: Midterm 2 Exercise 1: First Normal Form (1NF): Remove all repeating groups. Make a separate table for each set of related attributes, and give each table a primary key Second Normal Form (2NF): Remove partial dependencies. Eliminate redundant data. If an attribute depends on part of a multi-part(concatenated) key, remove it to a separate table. (assuming E-phone & B-Phone belong to instructor? If they belong to student, them should go to student. Assume, based on your original example, registration date, total fees and fees paid are applied to the student as a whole, not for each course. They should belong to student) STUDENT_COURSE (Student-ID+ Course-ID, Days/Time, Room/Bldg, Instructor, E-Phone, B-Phone ) STUDENT (Student-ID, S-Name, HomeAddr, Advisor, Ofc-Phone, RegisDate, TotalFees, FeesPaid ) COURSE (Course-ID, HoursCredit) Third Normal Form (3NF): Remove transitive dependencies. Eliminate columns not dependent on the primary key. If attributes do not contribute to a description of a key, move them to a separate table. STUDENT-COURSE (Student-ID + Course-ID [fk], Days/Time, Room/Bldg, Instructor[fk] ) SECTION(Course-ID[fk] + Days/Time, Room/Bldg, Instructor[fk] ) STUDENT (Student-ID, S-Name, HomeAddr, Advisor[fk], RegisDate, TotalFees, FeesPaid ) COURSE (Course-ID, HoursCredit ) ADVISOR (Advisor, Ofc-Phone) INSTRUCTOR (Instructor, E-Phone, B-Phone )

Exercise 3: SQL Queries: a/ Print title and price of all DVDs in the category Comedy, which cost less than 25 SR. Sort the output by the price (lowest price first). SELECT TITLE, PRICE FROM DVD WHERE CATEGORY = Comedy AND PRICE < 25 ORDER BY PRICE b/ Print number and title of all films (DVDs) that have an English audio track and got 5 stars from the user sb. SELECT E.NO, TITLE FROM EVALUATION E, AUDIOTRACK A, DVD D WHERE D.NO = E.NO AND E.NO = A.NO AND UID = sb AND LANGUAGE = English AND STARS = 5 c/ Print the title of all DVDs with an audio track in English and in Spanisch (both languages on the same DVD). SELECT TITLE FROM DVD D, AUDIOTRACK X, AUDIOTRACK Y WHERE X.NO = Y.NO AND D.NO = X.NO AND X.LANGUAGE = Spanisch AND Y.LANGUAGE = English d/ Which DVDs have only an Arabic audio track? Print the title of all such DVDs. SELECT TITLE FROM DVD D WHERE NO NOT IN (SELECT NO FROM AUDIOTRACK WHERE LANGUAGE <> arabic ) e/ Print for each DVD that was evaluated by at least two customers the title, the category, and the average evaluation (number of stars). The output column for the average evaluation should have the name GRADE. SELECT TITLE, CATEGORY, AVG(STARS) AS GRADE FROM DVD D, EVALUATION E WHERE D.NO = E.NO GROUP BY D.NO, TITLE, CATEGORY HAVING COUNT(*) >= 2 SQL CREATE TABLE: CREATE TABLE EVALUATION( NO NUMERIC(5) NOT NULL REFERENCES DVD, UID VARCHAR(20) NOT NULL, STARS NUMERIC(1) NOT NULL, TEXT VARCHAR(2000) NOT NULL, PRIMARY KEY(NO, UID), CONSTRAINT STARS_VALID CHECK(STARS BETWEEN 1 AND 5))

King Saud University College of Computer and Information Sciences Computer Science Department CSC380: Introduction to Database Instructor: Dr. Kamal Haouam Midterm: 2 Sunday: 11/02/1432 (16/01/2011) Time: 90mn Exercise 1: Given the following relation, expressed as: REGISTRATION CARD (Student-ID, S-Name, HomeAddr, Advisor, Ofc-Phone, {Course-ID, Days/Time, HoursCredit, Room/Bldg, Instructor}, E-Phone, B-Phone, RegisDate,TotalFees, FeesPaid) Construct the 1NF, 2NF, AND 3NF. Exercise 2: Given the following relation, expressed as (City, E#, EN, Skill,S, Age) with the typical data shown below, construct the 2NF. Show the answer in the notational form. City E# EN Skill S Age Riyadh 3 Fahed 3 4 24 Dammam 4 Naef 3 4 27 Dammam 2 Saoud 4 5 24 Dammam 3 Fahed 6 9 24 Riyadh 7 Bader 2 6 19 Madinah 2 Saoud 3 4 27 Exercise 3: An online shop for DVDs (video films) uses the following three tables: The first table contains the most important data of the DVDs. Each DVD has a unique number. The database does not contain any null values. DVD NO TITLE CATEGORY PRICE 1 Snow White Cartoon 27.99 2 New Shots! Part 2 Comedy 25.99 3 Fire Tongs Comedy 24.99 4 Spaceballs Comedy 19.99 In contrast to VHS video tapes, DVDs often contain several audio tracks in different languages. The second table contains this information. NO is a foreign key that refers to DVD.

AUDIOTRACK NO LANGUAGE 1 Arabic 1 English 2 Arabic 2 English 2 Spanish 3 Arabic 4 Arabic 4 English 4 French 4 Italian Finally, there is a table with evaluations of the DVDs by customers or users of the website. A user can rate a DVD by giving between one and five stars. NO is again a foreign key that refers to the table DVD. EVALUATION NO UID STARS TEXT 1 Sb 4 Sweet 1 Nina 3 Nice 1 Lisa 5 I watched it already 50 times. 2 Sb 4 funny 3 Sb 3 funny, but picture and sound quality not good. 4 Sb 5 Very funny 4 Nina 3 Well, Ok Questions:( SQL Queries) a) Print title and price of all DVDs in the category Comedy, which cost less than 25 SR. Sort the output by the price (lowest price first). In the example, the query result b) Print number and title of all films (DVDs) that have an English audio track and got 5 stars from the user sb. c) Print the title of all DVDs with an audio track in English and in Spanish (both languages on the same DVD). d) Which DVDs have only an Arabic audio track? Print the title of all such DVDs. e) Print for each DVD that was evaluated by at least two customers the title, the category, and the average evaluation (number of stars). The output column for the average evaluation should have the name GRADE. Questions: (SQL CREATE TABLE) Write a CREATE TABLE statement for the table EVALUATION. Declare the usual constraints (keys, foreign keys, NOT NULL). Use a CHECK-constraint to ensure that the attribute STARS can only take the values 1, 2, 3, 4, 5. The attribute NO is a decimal number of up to five digits. UID is a string up to length 20. TEXT is a string of maximal length 2000. Null values are not allowed in any column.

CSC380 Fall 2010 Questions Homework SQL Due date : January 11, 2011 Use the Mesri s database, found in my account, to answer the following questions: 1. Retrieve the name of male employees who were born before the year 1938 2. Retrieve the supervisor name for employees living at Houston and working at a department located at the same town. 3. List the different dependent relationships. 4. Retrieve the SSN of employees that do not work for any project controlled by department number 4. Explain: a) A natural join between works_on and project with a qualification dnum<>5 is not enough (expl: essn=333445555). b) Explain that we take employee and not works_on because an employee who does not have a project at all will be selected. 5. Retrieve the name of each employee who works on all projects controlled by department 5 (explain how the SQL will proceed to execute this statement) 6. For each employee, retrieve the name of his or her immediate supervisor. 7. For each department which it is assigned more than two employees, list the department number, the department name, the number of employees assigned and the average salary. 8. Create a view called project_summary, wich lists for each project the project number, the project name, the number of employees, and the minimum and maximum salary.

King Saud University College of Computer and Information Sciences Computer Science Department CSC380: Introduction to Database Instructor: Dr. Kamal Haouam Midterm: 1 Wednesday: 9/1/1432 (15/12/2010) Time: 90mn Question 1 : What is the main functionality of a DBMS? What is a foreign key constraint? Why are such constraints important? What is referential integrity? Given two relation schemas R(A1,A2) and S(A2,A3), define a relational algebra expression which is the equivalent of R JOIN S using only operations from the following list: union, difference, Cartesian product, projection, selection, renaming. Question 2 : The Tawuniya insurance company agrees to pay you to design and implement a database based on the following information: 1. A Person is identified by social security number. The person name and address must be recorded. 2. Cars are identified by license plate. For each car, the model, make, and year is recorded. 3. For each claim, the claim id, policy and description must be recorded. The claim id identifies a claim uniquely. 4. A car is owned by a person. 5. A policy holder itemizes elements of a claim by relating a car, a person, and a claim with a date and amount. 6. Multiple payments may be made from a claim to the person involved in the claim with values for amount and date of payment. Draw the ER diagram for this database. Map your ER diagram into a relational schema (show your keys and foreign keys).

Question 3 : Give the following queries in the relational algebra using the relational schema given above, that is student(id, name) enrolledin(id, code) subject(code, lecturer) 1. What are the names of students enrolled in CSC380? 2. Which subjects is Yazeed taking? 3. Who teaches CSC380? 4. What are the names of students in both CSC380 and CSC383? 5. What are the names of students taking a subject taught by Kamal? 6. Count the number of students enrolled in CSC380. Solution: Question 1 : DBMS enables users to create and maintain a database. A foreign key is a referential constraint between two tables. It identifies a column or a set of columns in one table that refers to a set of columns in another table. Referential integrity constraint is specified between two relations and is used to maintain the consistency among tuples in the two relations. Question 2 :

The schema is: Person(ssn, name, address) Car(license, state, model, make, year, owner) Car.owner foreign key to Person.ssn Claim(claimId, description, policy) ** Note: This is for 3-way relationship version. For weak entity version, Item.date is also a key field. Item(ssn, license, state, claimid, date, amount) Item.ssn foreign key to Person.ssn Item.claim foreign key to Claim.claimId Item.license and Item.state foreign key to Car.license and Car.state Payment(claimId, date, ssn, amount) Payment.ssn foreign key to Person.ssn Payment.claimId foreign key to Claim.claimId Note the primary key of payment depends on your assumptions. You could make it have an auto-number or some other system generated id in which case it is: Payment(id, ssn, claimid, date, amount) You could make Payment a weak entity dependent on claim id and use id or date as PPK: Payment(id, ssn, claimid, date, amount) OR Payment(ssn, claimid, date, amount) In all cases, there still is a foreign key on ssn and on claimid.

CSC380 Fall 2010 Tutorial 4 Solution THE RELATIONAL DATA MODEL AND RELATIONAL DATABASE CONSTRAINTS Exercise1: The schema of this question has the following four foreign keys: 1. the attribute SSN of relation ENROLL that references relation STUDENT, 2. the attribute Course# in relation ENROLL that references relation COURSE, 3. the attribute Course# in relation BOOK_ADOPTION that references relation COURSE, and 4. the attribute Book_ISBN of relation BOOK_ADOPTION that references relation TEXT. Exercise2: Answers: (a) No constraint violations. (b) Violates referential integrity because DNUM=2 and there is no tuple in the DEPARTMENT relation with DNUMBER=2. We may enforce the constraint by: (i) rejecting the insertion of the new PROJECT tuple, (ii) changing the value of DNUM in the new PROJECT tuple to an existing DNUMBER value in the DEPARTMENT relation, or (iii) inserting a new DEPARTMENT tuple with DNUMBER=2. (c) Violates both the key constraint and referential integrity. Violates the key constraint because there already exists a DEPARTMENT tuple with DNUMBER=4. We may enforce this constraint by: (i) rejecting the insertion, or (ii) changing the value of DNUMBER in the new DEPARTMENT tuple to a value that does not violate the key constraint. Violates referential integrity because MGRSSN='943775543' and there is no tuple in the EMPLOYEE relation with SSN='943775543'. We may enforce the constraint by: (i) rejecting the insertion, (ii) changing the value of MGRSSN to an existing SSN value in EMPLOYEE, or (iii) inserting a new EMPLOYEE tuple with SSN='943775543'.

(d) Violates both the entity integrity and referential integrity. Violates entity integrity because PNO, which is part of the primary key of WORKS_ON, is null. We may enforce this constraint by: (i) rejecting the insertion, or (ii) changing the value of PNO in the new WORKS_ON tuple to a value of PNUMBER that exists in the PROJECT relation. Violates referential integrity because ESSN='677678989' and there is no tuple in the EMPLOYEE relation with SSN='677678989'. We may enforce the constraint by: (i) rejecting the insertion, (ii) changing the value of ESSN to an existing SSN value in EMPLOYEE, or (iii) inserting a new EMPLOYEE tuple with SSN='677678989'. (e) No constraint violations. (f) No constraint violations. (g) Violates referential integrity because several tuples exist in the WORKS_ON, DEPENDENT, DEPARTMENT, and EMPLOYEE relations that reference the tuple being deleted from EMPLOYEE. We may enforce the constraint by: (i) rejecting the deletion, or (ii) deleting all tuples in the WORKS_ON, DEPENDENT, DEPARTMENT, and EMPLOYEE relations whose values for ESSN, ESSN, MGRSSN, and SUPERSSN, respectively, is equal to'987654321'. (h) Violates referential integrity because two tuples exist in the WORKS_ON relations that reference the tuple being deleted from PROJECT. We may enforce the constraint by: (i) rejecting the deletion, or (ii) deleting the tuples in the WORKS_ON relation whose value for PNO=1 (the value for the primary key PNUMBER for the tuple being deleted from PROJECT). (i) No constraint violations. (j) Violates referential integrity because the new value of SUPERSSN='943775543' and there is no tuple in the EMPLOYEE relation with SSN='943775543'. We may enforce the constraint by: (i) rejecting the deletion, or (ii) inserting a new EMPLOYEE tuple with SSN='943775543'. (k) No constraint violations.

CSC380 Fall 2010 Homework SQL Use the Mesri s database, found in my account, to answer the following questions: 1. Retrieve the name of male employees who were born before the year 1938 Select fname,lname,minit From employe Where sex= M and bdate<to_date( 01-jan-1938 ); 2. Retrieve the supervisor name for employees living at Houston and working at a department located at the same town. 3. List the different dependent relationships. Select E2.fname, E2.minit,E2.lname From employee E1, employee E2, dept_location Where E2.dno=dnumber and E1.superssn=E2.ssn; Dlocation= Houston and E1.address like %Houston% ; Select distinct relationship From dependent; 4. Retrieve the SSN of employees that do not work for any project controlled by department number 4. Select ssn From employee Where ssn not in (select essn from works_on, project where pnumber=pno and dnum=4); 5. Retrieve the name of each employee who works on all projects controlled by department 5 (explain how the SQL will proceed to execute this statement) select Fname, lname from employee where not exists (select * from works_on B, project where pno=pnumber and dnum=5 and not exists (select * from works_on C where B.pno=C.pno and C.essn=ssn)); 1

6. For each employee, retrieve the name of his or her immediate supervisor. Select E1.SSN, E2.fname,E2.minit,E2.lname From employee E1, employee E2 Where E1.superssn=e2.ssn(+); 7. For each department which it is assigned more than two employees, list the department number, the department name, the number of employees assigned and the average salary. Select dnumber, dname, count(*), avg(salary) From department, employee Where dno=dnumber Group by dnumber, dname Having count(*)>2; 8. Create a view called project_summary, wich lists for each project the project number, the project name, the number of employees, and the minimum and maximum salary. Create view project_summary (pnumber, pname, nb_empl, min_sal, max_sal) as Select pnumber, pname, count(*), min(salary), max(salary) From employee, works_on, project Where pno=pnumber and Essn=ssn Group by pnumber,pname. 2