The Requirements for a Company Database

Total Page:16

File Type:pdf, Size:1020Kb

The Requirements for a Company Database

DCIS850-doylet Page 1

Running Head: DCIS850-doylet

Project Option II

Final Project Report – July 31, 2004

DCIS 850 – Project in Database Systems

Fernando E. Doylet

Graduate School of Computer and Information Sciences

Nova Southeastern University DCIS850-doylet Page 2

Table of Content

1. Partition the sentences...... 3 Universal_Relation...... 5 Unspecified Requirements:...... 6 Appropriate Assumptions:...... 6 Additional Assumptions:...... 6 2. Design the conceptual schema...... 7 3. Relational database schema...... 9 4. List all the join paths...... 10 5. Normalize relation schema...... 11 6. Implement the database...... 14 7. Implement the given queries...... 30 1. List all the relations in the database...... 30 2. List all the attributes and type definitions for each table...... 30 3. List all the tuples in each table...... 33 5. For each employee, show how many projects the employee works on...... 45 6. For each employee, show how many projects the employee manages...... 46 7. For each employee, show how many dependents the employee has...... 46 8. For each employee, as a supervisor, how many supervisees the employee supervises...... 47 9. List the suplier names of suppliers who supply all parts...... 48 10. Get part numbers for parts supplied by a supplier in London...... 48 11. Get project names for projects supplied by Supplier 1...... 48 12. Get the list of subparts used by each part...... 49 13. Get the part numbers for parts supplied to all projects in London...... 49 14. Get supplier numbers for suppliers supplying some project with part Part 1 in a quantity greater than the average shipment quantity of part Part 1 for that project...... 49 15. Get supplier numbers for suppliers who supply the same part to all projects. 50 16. For each part, list all its direct and indirect subparts that belong to the part.. .50 17. For each employee, list all his/her direct or indirect supervisees the employee supervises...... 51 18. List the employees who work on all the projects except the project control by Department 4...... 53 19. List the projects worked by every employee...... 53 20. List the departments that controls all the projects that Joyce English works on...... 54 8. Write a detailed report...... 56 DCIS850-doylet Page 3

1. Partition the sentences Partition the sentences (database requirement description in natural language) into homogeneous groups

DEPARTMENT The company is organized into many departments. Each NAME department has a name, a number, and an employee who manages NUMBER the department. We keep track of the start date when that MANAGER employee started managing the department MGR-START-DT

DEPT-LOC DEPT-NUM A department may have several locations. LOCATION

EMPLOYEE NAME SSN ADDRESS We store each employee’s name, social security number, address, SALARY salary, sex, and birth date. Employees are classified into managers, SEX technicians, engineers, or secretaries based on job types, and can also BIRTHDATE classified into salary-employee or hourly-employee. JOB-TYPE SAL-HOUR DEPT-NUM

HOURS An employee is assigned to one department but may work on EMP-SSN several projects, which are not necessarily controlled by the same PROJECT department. We keep track of the number of hours per week that an WEEK-HOURS employee works on each project.

PROJECT Each project may be worked by several employee workers. Some NAME employee may manage several projects, but only one manager for each MANAGER project. DCIS850-doylet Page 4

EMPLOYEE NAME SSN ADDRESS SALARY SEX We also keep track of the direct supervisor of each employee. BIRTHDATE JOB-TYPE SAL-HOUR DEPT-NUM SUPERVISOR

PART NUMBER Each project uses a certain number of parts supplied by suppliers. DESCRIPTION

SUPPLY Each part may be supplied by different suppliers (different suppliers PART may supply the same parts) and each supplier supplies different parts. SUPPLIER

SUPPLIER NUMBER We keep track of each supplier with supplier number, supplier name, NAME status (rating or status value), and city (location). Each supplier is STATUS located in exactly one city. CITY

PART NUMBER Parts are also kept track of with part number, part name, color, NAME weight and city (location) where the parts of that type are stored COLOR (only one location). Each part may consist of several other parts WEIGHT (subparts), each part may be used by several other parts as subparts. CITY SUBPART-OF

DEPENDENT ESSN We want to keep track of the dependents of each employee for NAME insurance purposes. We keep each dependent’s name, sex, birth SEX date, and relationship to the employee. BIRTHDATE RELATIONSHIP DCIS850-doylet Page 5

FD1 FD2 FD3 FD4 FD5 FD8 FD12 DEPARTMENT_NAME Universal Relation including all the database attributes DEPARTMENT_NUMBER & showing all the functional dependencies DEPARTMENT_MANAGER that should hold among the attributes

DEPT_MGR_START_DATE

DEPT_LOCATION(S) Universal_Relation

EMPLOYEE_NAME_FIRST Functional Dependencies:

EMPLOYEE_NAME_MI FD1: The company is organized into many departments. Each department has a name, a EMPLOYEE_NAME_MAIDEN number...... A department may have several EMPLOYEE_NAME_LAST locations. FD6 EMPLOYEE_SSN FD2: Each department has an employee who manages the department. We keep track of the start EMPLOYEE_SALARY date when that employee started managing the department. EMPLOYEE_SEX

EMPLOYEE_BIRTHDATE FD3: We store each employee's name, social security number, address, salary, sex, and birth date. EMPLOYEE_JOB_TYPE Employees are classified into managers, technicians, engineers, or secretaries based on job types, and can EMP_SALARY_OR_HOURLY also classified into salary-employee or hourly- EMPLOYEE_ADDR_LINE1 employee. An employee is assigned to one department. EMPLOYEE_ADDR_LINE2 FD4: An employee may work on several projects...... EMPLOYEE_ADDR_CITY We keep track of the number of hours per week that an employee works on each project. EMPLOYEE_ADDR_ZIP

EMPLOYEE_ADDR_TYPE FD5: Projects are not necessarily controlled by the same department. EMP_PHONE_NUMBER(S) FD7 FD9 FD6: Each project may be worked by several PROJECT_NAME employee workers. EMP_PROJ_HOURS/WEEK FD7: Some employee may manage several projects, PROJECT_MANAGER but only one manager for each project.

EMPLOYEE_SUPERVISOR FD8: We also keep track of the direct supervisor of FD11 each employee. PART_NUMBER FD10 PART_SUPPLIER FD9: Each project uses a certain number of parts supplied by suppliers. Each part may be supplied by SUPPLIER_NUMBER different suppliers (different suppliers may supply the same parts) and each supplier supplies different SUPPLIER_NAME parts. SUPPLIER_STATUS FD10: We keep track of each supplier with supplier SUPPLIER_CITY number, supplier name, status (rating or status value), and city (location). Each supplier is located in PART_NAME exactly one city.

PART_COLOR FD11: Parts are also kept track of with part number, PART_WEIGHT part name, color, weight and city (location) where the parts of that type are stored (only one location). Each PART_CITY part may consist of several other parts (subparts), each part may be used by several other parts as PART_SUBPART_OF subparts. EMP_DEPENDENT_NAME FD12: We want to keep track of the dependents of EMP_DEPENDENT_SEX each employee for insurance purposes. We keep each dependent's name, sex, birth date, and EMP_DEPEND_BIRTHDATE relationship to the employee.

EMP_DEPEND_RELATION DCIS850-doylet Page 6

Unspecified Requirements:

UR1: Employees may have permanent and temporary addresses

UR2: Employees must have complete contact information

UR3: Address labels should be retrievable from the database

UR4: Address labels could be sorted by last name of Employee

Appropriate Assumptions:

AA1: Each Employee may have several addresses

AA2: Each Employee may have several telephone numbers

AA3: Each Address consists of two address lines, city, zip and type (type options:

permanent, vacation, temporary, family, etc.)

AA4: Each Employee name consists of first, mi, maiden and last name

Additional Assumptions:

AA5: Each Employee has only one job type, regardless of his/her Supervisory or

Managerial activities.

AA6: Each Project is located in the City where its managing Department is located.

AA7: Employee searches by last name must include the optional maiden name.

AA8: To include area code, extension number, or other digits or characters required,

telephone numbers are stored as free-flow text. DCIS850-doylet Page 7

2. Design the conceptual schema

Design the conceptual schema of the company database by using ER diagram and CSDL (Conceptual Schema Definition Language). Your conceptual design of the database should include the following but not limited to:

a. Entities b. Subclasses and Superclasses c. Relationships d. Keys e. Structural constraints (Cardinality ratio and participation constraints)

ER Diagram

Number Mgr-Start-Dt Maiden Last JobType Sal-Hour MI Birthdate First Ssn Name Location Salary Sex Name Telephone

DEPARTMENT 1 WORK N EMPLOYEE 1 1 1 N

1 MANAGED_BY N MANAGER

1 SUPERVISES N CONTROLS 1 WORKS_ON MANAGES

N Name N Week-Hours

N

PROJECT SUPPORTS Address

N Line1 Description Zip

Number Number Name Status City Line2 USES City Type Name N

Color N PART N SUPPLIED N SUPPLIER Weight

City N N Name Birthdate Sex Relationship Quantity

SUBPART-OF DEPENDENT DCIS850-doylet Page 8

Conceptual Schema Schema: COMPANY

Entity: DEPARTMENT Entity: EMPLOYEE Attributes: DEPT_NAME: text(50) Attributes: SSN: integer DEPT_NUMBER: integer JOBTYPE: text(10) MGR-START-DATE: text(10) SALARY: integer Identifiers: DEPT_NUMBER SAL-HOUR: text(10) EMP_SEX: text(10) Multivalue: LOCATION EMP_BIRTHDATE: text(10) Attributes: DEPT_NUMBER: integer EMP_DEPT_NUMBER: integer DEPT_LOCATION: text(50) EMP_SUPERV_SSN: integer Identifiers: DEPT_NUMBER, Composite: FIRST_NAME: text(50) DEPT_LOCATION MI: text(1) MAIDEN_NAME: text(50) LAST_NAME: text(50) Relationship: WORK Identifiers: SSN Connected Entities: (1,n) DEPARTMENT (1,1) EMPLOYEE Multivalue: TELEPHONE Attributes: SSN: integer Relationship: MANAGED_BY PHONE_NUMBER: text(20) Connected Entities: (1,1) DEPARTMENT PHONE_TYPE: text(50) (1,1) EMPLOYEE Identifiers: SSN, PHONE_NUMBER

Subclass: MANAGER Composite: ADDRESS Superclass: EMPLOYEE (& Multivalue) Participation: Partial Attributes: SSN: integer TYPE: text(50) LINE1: text(50) Entity: PROJECT LINE2: text(50) Attributes: PROJ_NAME: text(50) CITY: text(50) PROJ_NUMBER: integer ZIP: text(10) PROJ_MGR_SSN: integer Identifiers: SSN, TYPE PROJ_DEPT_NUM: integer Identifiers: PROJ_NUMBER Entity: DEPENDENT Relationship: MANAGES Attributes: DEP_NAME: text(50) Connected Entities: (1,1) MANAGER DEP_BIRTHDATE: text(10) (1,n) PROJECT DEP_SEX: text(10) DEP_RELATION: text(50) Identifiers: DEP_NAME, Relationship: WORKS_ON DEP_BIRTHDATE Connected Entities: (1,n) EMPLOYEE (1,n) PROJECT Attribute: Week-Hours Relationship: SUPPORTS Connected Entities: (1,n) EMPLOYEE (1,1) DEPENDENT Relationship: CONTROLS Connected Entities: (1,n) DEPARTMENT (1,1) PROJECT Entity: PART Attributes: DESCRIPTION: text(50) PART_NUMBER: integer Entity: SUPPLIER PART_NAME: text(50) Attributes: SUPPLIER_NUM: integer COLOR: text(20) SUPPLIER_NAME: text(50) WEIGHT: integer STATUS: text(30) PART_CITY: text(30) SUPPLIER_CITY: text(30) SUBPART_OF: integer Identifiers: SUPPLIER_NUMBER Identifiers: PART_NUMBER

Relationship: USES Relationship: SUPPLIED_BY Connected Entities: (1,n) PROJECT Connected Entities: (1,n) PART (1,n) PART (1,n) SUPPLIER Attributes: QUANTITY: integer Relationship: SUBPART_OF Connected Entities: (1,n) PART Relationship: SUPERVISES (1,n) PART Connected Entities: (1,n) EMPLOYEE (1,1) EMPLOYEE DCIS850-doylet Page 9

3. Relational database schema Transform the ER schema of database you get from step 2 into the corresponding relational database schema

a. Specify all the key attributes of relations and any referential integrity constraints. b. Specify the data item format for each attribute in each relation schema. c. Specify all the functional dependencies you could infer from the requirements.

Relational Database Schema

DEPARTMENT EMPLOYEE DEPT_NAME text(50) PK EMP_SSN integer PK DEPT_NUMBER integer EMP_NAME_FIRST text(50) FK DEPT_MGR_SSN integer EMP_NAME_MI text(1) DEPT_MGR-START-DT text(10) EMP_NAME_MAIDEN text(50) EMP_NAME_LAST text(50) EMP_JOBTYPE text(10) LOCATION EMP_SALARY integer PK,FK LOC_DEPT_NUM integer EMP_SAL-HOUR text(10) PK LOC_CITY text(50) EMP_SEX text(10) EMP_BIRTHDATE text(10) PROJECT FK EMP_DEPT_NUMBER integer PK PROJ_NUM integer FK EMP_SUPERVISOR_SSN integer PROJ_NAME text(50) FK PROJ_MGR_SSN integer FK PROJ_DEPT_NUM integer TELEPHONE PK,FK TEL_SSN integer PK TEL_NUM text(20) WORKS_ON TEL_TYPE text(50) PK,FK WO_SSN integer PK,FK WO_PROJ_NUM integer WEEK-HOURS float ADDRESS PK,FK ADD_SSN integer PK ADD_TYPE text(50) PART ADD_LINE1 text(50) PK PART_NUM integer ADD_LINE2 text(50) PART_NAME text(50) ADD_CITY text(50) PART_DESC text(50) ADD_ZIP text(10) PART_COLOR text(20) PART_WEIGHT integer PART_CITY text(30) DEPENDENT PK,FK DEP_EMP_SSN integer PK DEP_NAME text(50) SUBPART_OF PK DEP_BIRTHDATE text(10) PK,FK SO_PART integer DEP_SEX text(10) PK,FK SO_SUBPART integer DEP_RELATION text(50)

USES SUPPLIER PK,FK USE_PROJECT integer PK SUP_NUM integer PK,FK USE_PART integer SUP_NAME text(50) SUP_STATUS text(30) SUP_CITY text(30) SUPPLIED_BY PK,FK SB_PART inteer PK,FK SB_SUPPLIER integer QUANTITY integer DCIS850-doylet Page 10

4. List all the join paths List all the join paths existing in the relational database schema you get from the transformation in step 3.

ER Relationship Participating Relations Join Condition

EMPLOYEE EMPLOYEE EMP_SUPERVISOR_SSN = EMP_SSN EMPLOYEE DEPARTMENT EMP_DEPT_NUMBER = DEPT_NUMBER DEPARTMENT EMPLOYEE DEPT_MGR_SSN = EMP_SSN LOCATION DEPARTMENT LOC_DEPT_NUM = DEPT_NUMBER TELEPHONE EMPLOYEE TEL_SSN = EMP_SSN ADDRESS EMPLOYEE ADD_SSN = EMP_SSN PROJECT EMPLOYEE PROJ_MGR_SSN = EMP_SSN PROJECT DEPARTMENT PROJ_DEPT_NUM = DEPT_NUMBER WORKS_ON EMPLOYEE WO_SSN = EMP_SSN WORKS_ON PROJECT WO_PROJ_NUM = PROJ_NUM DEPENDENT EMPLOYEE DEP_EMP_SSN = EMP_SSN SUBPART_OF PART SO_PART = PART_NUM SUBPART_OF PART SO_SUBPART = PART_NUM USES PROJECT USE_PROJECT = PROJ_NUM USES PART USE_PART = PART_NUM SUPPLIED_BY PART SB_PART = PART_NUM SUPPLIED_BY SUPPLIER SB_SUPPLIER = SUP_NUM DCIS850-doylet Page 11

5. Normalize relation schema Normalize relation schema in the database design that you get from step 4 into either 3NF of BCNF if it is necessary. Taking each Functional Dependency (FD) from the Universal Relation shown under question 1. Partition the sentences, the normalization is reasoned as follows…

FD1 FD2 DEPARTMENT is in non-first normal form DEPARTMENT_NAME (non-1NF) because DEPT_LOCATION(S) is not

DEPARTMENT_NUMBER an atomic value. After normalization, two tables are generated in 1NF, DEPARTMENT and DEPARTMENT_MANAGER LOCATION, which are in 2NF because all non- DEPT_MGR_START_DATE prime attributes are fully functional dependent on DEPT_LOCATION(S) the primary key.

DEPARTMENT LOCATION Both tables are in 3NF because DEPARTMENT_NAME DEPARTMENT_NUMBER there are no transitive or partial

DEPARTMENT_NUMBER DEPT_LOCATION dependencies, and in BCNF because there are no trivial DEPARTMENT_MANAGER dependencies included. DEPT_MGR_START_DATE

FD3 FD8 Employee details are in non-1NF because each DEPARTMENT_NUMBER employee may have more than one address or EMPLOYEE_NAME_FIRST phone number, so after leaving only atomic fields, the remaining EMPLOYEE fields are EMPLOYEE_NAME_MI already in 3NF without any transitive or partial EMPLOYEE_NAME_MAIDEN dependency, and BCNF without trivial EMPLOYEE_NAME_LAST dependencies.

EMPLOYEE_SSN Since FD8 requires tracking of the Supervisor of EMPLOYEE_SALARY each Employee, the field is added to produce the EMPLOYEE_SEX table shown below.

EMPLOYEE_BIRTHDATE From the employee fields, three separate tables, EMPLOYEE_JOB_TYPE ADDRESS, TELEPHONE and EMPLOYEE are EMP_SALARY_OR_HOURLY extracted; a field to identify the type of

EMPLOYEE_ADDR_LINE1 telephone is added. Like EMPLOYEE, ADDRESS and TELEPHONE are single key EMPLOYEE_ADDR_LINE2 tables in 2NF; without transitive or partial EMPLOYEE_ADDR_CITY dependencies they are in 3NF; and without EMPLOYEE_ADDR_ZIP trivial dependencies, both tables are in BCNF.

EMPLOYEE_ADDR_TYPE

EMP_PHONE_NUMBER(S)

EMPLOYEE_SUPERVISOR DCIS850-doylet Page 12

ADDRESS TELEPHONE EMPLOYEE EMPLOYEE_SSN EMPLOYEE_SSN EMPLOYEE_NAME_FIRST

EMPLOYEE_ADDR_LINE1 EMP_PHONE_NUMBER EMPLOYEE_NAME_MI

EMPLOYEE_ADDR_LINE2 EMP_PHONE_TYPE EMPLOYEE_NAME_MAIDEN

EMPLOYEE_ADDR_CITY EMPLOYEE_NAME_LAST

EMPLOYEE_ADDR_ZIP EMPLOYEE_SSN

EMPLOYEE_ADDR_TYPE EMPLOYEE_SALARY

EMPLOYEE_SEX

EMPLOYEE_BIRTHDATE

EMPLOYEE_JOB_TYPE

EMP_SALARY_OR_HOURLY

EMPLOYEE_SUPERVISOR

EMP_DEPARTMENT_NUM

FD7 FD4 FD5 FD6 Combining FD4, FD5, FD6 and FD7, DEPARTMENT_NUMBER two tables are extracted, PROJECT and WORKS_ON. EMPLOYEE_SSN To avoid data entry errors, a ‘Project PROJECT_NAME Number’ attribute complements each

EMP_PROJ_HOURS/WEEK similar ‘Project Name’, which is used to build the join table required to log the PROJECT_MANAGER hours per week each Employee may work on separate Projects.

PROJECT WORKS_ON In both tables, all non-prime PROJECT_NUMBER EMPLOYEE_SSN attributes are fully functional

PROJECT_NAME PROJECT_NUMBER dependent on their primary keys, and without transitive, PROJECT_MANAGER EMP_PROJ_HOURS/WEEK partial or trivial PROJECT_DEPT_NUM dependencies, both tables are in BCNF.

FD10 PART_SUPPLIER Postponing FD9 to build its related tables, all the Supplier details in FD10 produce a table in BCNF. SUPPLIER_NUMBER SUPPLIER_NAME SUPPLIER SUPPLIER_STATUS SUPPLIER_NUMBER

SUPPLIER_CITY SUPPLIER_NAME SUPPLIER_STATUS

SUPPLIER_CITY DCIS850-doylet Page 13

FD11 Likewise, most of the Part details produce the table PART_NUMBER PART in BCNF.

PART_NAME On the other hand, since any part could be a subpart of PART_COLOR many parts and also could have many subparts, the PART_WEIGHT SUBPART_OF join table needs to be created. With PART_CITY only two fields depending on each other, this table is also in BCNF. PART_SUBPART_OF

PART SUBPART_OF PART_NUMBER PART_NUMBER

PART_NAME PART_SUBPART_OF

PART_COLOR

PART_WEIGHT

PART_CITY

PART_DESCRIPTION

FD9 After the Project and Supplier and Part tables have been PROJECT_NAME identified, their relationships specified by FD9 PART_NUMBER determine the creation of two tables. Both are join tables needed by their many-to-many relationships. PART_SUPPLIER

USES SUPPLIED BY An additional field is added to PROJECT_NUMBER PART_NUMBER keep track of the Quantity of parts

PART_NUMBER SUPPLIER_NUMBER supplied by each Supplier. Both tables are in BCNF. QUANTITY

FD12 The attributes remaining from the Universal Relation are EMPLOYEE_SSN part of FD12, which produce a DEPENDENT table. EMP_DEPENDENT_NAME Since the same Employee may have more than one dependent with the same name or birthday, all these EMP_DEPENDENT_SEX fields form the composite primary key. With all non- EMP_DEPEND_BIRTHDATE prime attributes fully functional dependent on their EMP_DEPEND_RELATION composite primary key, and without transitive, partial or trivial dependencies, this table is in BCNF. DCIS850-doylet Page 14

DEPENDENT EMPLOYEE_SSN

EMP_DEPENDENT_NAME

EMP_DEPENDENT_SEX

EMP_DEPEND_BIRTHDATE

EMP_DEPEND_RELATION

6. Implement the database Implement the database you get in step 5, via ORACLE/SQL*PLUS or other DBMS available to you, this includes creating the database, creating the corresponding relation schemas, data preparation and loading data into the database.

SQL> get dropTables; 1 DROP TABLE SUPPLIED_BY; 2 DROP TABLE USES; 3 DROP TABLE SUBPART_OF; 4 DROP TABLE PART; 5 DROP TABLE SUPPLIER; 6 DROP TABLE DEPENDENT; 7 DROP TABLE ADDRESS; 8 DROP TABLE TELEPHONE; 9 DROP TABLE WORKS_ON; 10 DROP TABLE PROJECT; 11 DROP TABLE LOCATION; 12 ALTER TABLE EMPLOYEE DROP CONSTRAINT EMPDEPTFK; 13 DROP TABLE DEPARTMENT; 14* DROP TABLE EMPLOYEE;

SQL> start dropTables;

Table dropped. Table dropped. Table dropped. Table dropped. Table dropped. Table dropped. Table dropped. Table dropped. Table dropped. Table dropped. Table dropped. Table altered. Table dropped. Table dropped.

SQL> get tables;

1 CREATE TABLE DEPARTMENT 2 ( dept_name VARCHAR(50) NOT NULL, 3 dept_number INT PRIMARY KEY, 4 dept_mgr_ssn INT, 5 dept_mgr_start_dt DATE);

6 CREATE TABLE LOCATION 7 ( loc_dept_num INT, 8 loc_city VARCHAR(50), DCIS850-doylet Page 15

9 PRIMARY KEY (loc_dept_num, loc_city), 10 CONSTRAINT LOCDEPTFK 11 FOREIGN KEY (loc_dept_num) REFERENCES DEPARTMENT(dept_number));

12 CREATE TABLE EMPLOYEE 13 ( emp_ssn INT PRIMARY KEY, 14 emp_name_first VARCHAR(50) NOT NULL, 15 emp_name_mi CHAR(1), 16 emp_name_maiden VARCHAR(50), 17 emp_name_last VARCHAR(50) NOT NULL, 18 emp_jobtype VARCHAR(10), 19 emp_salary INT, 20 emp_sal_hour VARCHAR(10), 21 emp_sex CHAR(1), 22 emp_birthdate DATE, 23 emp_dept_number INT, 24 emp_supervisor_ssn INT, 25 CONSTRAINT EMPDEPTFK 26 FOREIGN KEY (emp_dept_number) REFERENCES DEPARTMENT(dept_number), 27 CONSTRAINT EMPEMPFK 28 FOREIGN KEY (emp_supervisor_ssn) REFERENCES EMPLOYEE (emp_ssn));

29 ALTER TABLE DEPARTMENT ADD CONSTRAINT DEPTEMPFK 30 FOREIGN KEY (dept_mgr_ssn) REFERENCES EMPLOYEE (emp_ssn);

31 CREATE TABLE PROJECT 32 ( proj_num INT PRIMARY KEY, 33 proj_name VARCHAR(50) NOT NULL, 34 proj_mgr_ssn INT, 35 proj_dept_num INT NOT NULL, 36 CONSTRAINT PROJEMPFK 37 FOREIGN KEY (proj_mgr_ssn) REFERENCES EMPLOYEE (emp_ssn), 38 CONSTRAINT PROJDEPTFK 39 FOREIGN KEY (proj_dept_num) REFERENCES DEPARTMENT (dept_number));

40 CREATE TABLE TELEPHONE 41 ( tel_ssn INT, 42 tel_num VARCHAR(20), 43 tel_type VARCHAR(50) DEFAULT 'UNKNOWN', 44 PRIMARY KEY (tel_ssn, tel_num), 45 CONSTRAINT TELEMPFK 46 FOREIGN KEY (tel_ssn) REFERENCES EMPLOYEE (emp_ssn));

47 CREATE TABLE WORKS_ON 48 ( wo_ssn INT, 49 wo_proj_num INT, 50 week_hours DECIMAL(5,2), 51 PRIMARY KEY (wo_ssn, wo_proj_num), 52 CONSTRAINT WOEMPFK 53 FOREIGN KEY (wo_ssn) REFERENCES EMPLOYEE (emp_ssn), 54 CONSTRAINT WOPROJFK 55 FOREIGN KEY (wo_proj_num) REFERENCES PROJECT (proj_num));

56 CREATE TABLE ADDRESS 57 ( add_ssn INT, 58 add_type VARCHAR(50), 59 add_line1 VARCHAR(50) NOT NULL, 60 add_line2 VARCHAR(50), 61 add_city VARCHAR(50) NOT NULL, 62 add_zip VARCHAR(10) NOT NULL, 63 PRIMARY KEY (add_ssn, add_type), 64 CONSTRAINT ADDEMPFK 65 FOREIGN KEY (add_ssn) REFERENCES EMPLOYEE (emp_ssn)); DCIS850-doylet Page 16

66 CREATE TABLE PART 67 ( part_num INT PRIMARY KEY, 68 part_name VARCHAR(50) NOT NULL, 69 part_desc VARCHAR(50), 70 part_color VARCHAR(20), 71 part_weight INT, 72 part_city VARCHAR(30) NOT NULL);

73 CREATE TABLE DEPENDENT 74 ( dep_emp_ssn INT, 75 dep_name VARCHAR(50), 76 dep_birthdate DATE, 77 dep_sex VARCHAR(10), 78 dep_relation VARCHAR(50), 79 PRIMARY KEY (dep_emp_ssn, dep_name, dep_birthdate), 80 CONSTRAINT DEPEMPFK 81 FOREIGN KEY (dep_emp_ssn) REFERENCES EMPLOYEE (emp_ssn));

82 CREATE TABLE SUBPART_OF 83 ( so_part INT, 84 so_subpart INT, 85 PRIMARY KEY (so_part, so_subpart), 86 CONSTRAINT SOPARTFK 87 FOREIGN KEY (so_part) REFERENCES PART (part_num), 88 CONSTRAINT SOPART2FK 89 FOREIGN KEY (so_subpart) REFERENCES PART (part_num));

90 CREATE TABLE USES 91 ( use_project INT, 92 use_part INT, 93 PRIMARY KEY (use_project, use_part), 94 CONSTRAINT USEPROJFK 95 FOREIGN KEY (use_project) REFERENCES PROJECT (proj_num), 96 CONSTRAINT USEPARTFK 97 FOREIGN KEY (use_part) REFERENCES PART (part_num));

98 CREATE TABLE SUPPLIER 99 ( sup_num INT PRIMARY KEY, 100 sup_name VARCHAR(50) NOT NULL, 101 sup_status VARCHAR(30), 102 sup_city VARCHAR(30) NOT NULL);

103 CREATE TABLE SUPPLIED_BY 104 ( sb_part INT, 105 sb_supplier INT, 106 quantity INT DEFAULT 0, 107 PRIMARY KEY (sb_part, sb_supplier), 108 CONSTRAINT SBPARTFK 109 FOREIGN KEY (sb_part) REFERENCES PART (part_num), 110 CONSTRAINT SBSUPFK 111* FOREIGN KEY (sb_supplier) REFERENCES SUPPLIER (sup_num)); 112 SQL> start tables;

Table created. Table created. Table created. Table altered. Table created. Table created. Table created. Table created. DCIS850-doylet Page 17

Table created. Table created. Table created. Table created. Table created. Table created.

SQL> get fillDepartment; 1 INSERT INTO DEPARTMENT VALUES ('Accounting',1,null,'20-JUN-78'); 2 INSERT INTO DEPARTMENT VALUES ('Management',2,null,'15-NOV-80'); 3 INSERT INTO DEPARTMENT VALUES ('Personnel',3,null,null); 4 INSERT INTO DEPARTMENT VALUES ('Marketing',4,null,null); 5* INSERT INTO DEPARTMENT VALUES ('Human Resources',5,null,null);

SQL> start fillDepartment;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillEmployee; 1 INSERT INTO EMPLOYEE VALUES (123456789,'Edward','F',null,'Kling','Manager',75000,'H','M','13-DEC- 58',1,null); 2 INSERT INTO EMPLOYEE VALUES (543219876,'Peter','D',null,'Sucre','Engineer',60000,'S','M','30-AUG- 65',1,123456789); 3 INSERT INTO EMPLOYEE VALUES (987654321,'Ernest','E',null,'De La Torre','Technician',40000,'S','M','15-SEP-64',1,543219876); 4 INSERT INTO EMPLOYEE VALUES (010203040,'Irma','A','Landivar','Torres','Secretary',28000,'H','F','17-MAY- 76',1,543219876); 5 INSERT INTO EMPLOYEE VALUES (918273645,'Francis','C','Terranova','Carbo','Secretary',30000,'H','F','02- FEB-74',1,987654321); 6 INSERT INTO EMPLOYEE VALUES (098765432,'Gladys','B',null,'Davila','Secretary',25000,'H','F','12-MAR- 80',1,123456789); 7 INSERT INTO EMPLOYEE VALUES (919293949,'Anna','G','Barbas','Lobos','Technician',45000,'S','F','05-OCT- 62',1,123456789); 8 INSERT INTO EMPLOYEE VALUES (182838485,'Dana','H',null,'Thomas','Manager',70000,'S','F','23-AUG- 59',2,null); 9 INSERT INTO EMPLOYEE VALUES (564636261,'Carol','J','Crocker','Terrell','Engineer',43500,'S','F','10-APR- 60',2,182838485); 10 INSERT INTO EMPLOYEE VALUES (908070605,'Jeffrey','K',null,'Denny','Engineer',42000,'H','M','14-JAN- 63',2,182838485); 11 INSERT INTO EMPLOYEE VALUES (273747576,'John','I',null,'Jasso','Technician',35000,'S','M','05-JUL- 66',2,564636261); 12 INSERT INTO EMPLOYEE VALUES (403020109,'Ashley','L',null,'David','Secretary',28500,'H','F','25-NOV- 70',2,908070605); 13 INSERT INTO EMPLOYEE VALUES (101918171,'Sam','M',null,'Ramseyer','Technician',33000,'S','M','30-AUG- 66',2,908070605); 14 INSERT INTO EMPLOYEE VALUES (292827262,'Brenda','N','Douglas','Olive','Secretary',25678,'S','F','22-OCT- DCIS850-doylet Page 18

72',2,564636261); 15 INSERT INTO EMPLOYEE VALUES (321098678,'Addiel','O',null,'Millan','Manager',65000,'S','M','24-NOV- 48',3,null); 16 INSERT INTO EMPLOYEE VALUES (110220330,'Ronald','P',null,'Torrido','Engineer',44530,'S','M','03-OCT- 61',3,321098678); 17 INSERT INTO EMPLOYEE VALUES (220330440,'Estuardo','Q',null,'Sanchez','Technician',35440,'H','M','14-DEC- 61',3,110220330); 18 INSERT INTO EMPLOYEE VALUES (400300200,'Frank','R',null,'Imparato','Technician',33420,'H','M','12-JAN- 63',3,110220330); 19 INSERT INTO EMPLOYEE VALUES (505958575,'Dorothy','S',null,'Hale','Secretary',28500,'H','F','18-FEB- 73',3,220330440); 20 INSERT INTO EMPLOYEE VALUES (483920756,'Eunice','T','Zurita','Duran','Secretary',27600,'H','F','29-MAR- 75',3,110220330); 21 INSERT INTO EMPLOYEE VALUES (928372891,'Joyce','U','English','Gamboa','Secretary',26000,'S','F','21-APR- 77',3,321098678); 22 INSERT INTO EMPLOYEE VALUES (061928473,'Monica','V',null,'Okeefe','Manager',62340,'H','F','12-DEC- 55',4,null); 23 INSERT INTO EMPLOYEE VALUES (551552553,'Marie','W',null,'Green','Engineer',47890,'H','F','11-NOV- 60',4,061928473); 24 INSERT INTO EMPLOYEE VALUES (440449448,'Linda','X',null,'Ogus','Engineer',45670,'H','F','10-OCT- 65',4,061928473); 25 INSERT INTO EMPLOYEE VALUES (334335336,'Robert','Y',null,'Mueller','Technician',38540,'S','M','09-SEP- 79',4,551552553); 26 INSERT INTO EMPLOYEE VALUES (123321123,'Roger','Z',null,'Mekala','Technician',34350,'S','M','08-AUG- 75',4,551552553); 27 INSERT INTO EMPLOYEE VALUES (987789987,'Richard','A',null,'Laux','Secretary',29340,'S','M','07-JUL- 80',4,440449448); 28 INSERT INTO EMPLOYEE VALUES (768594032,'Kevin','B',null,'Jones','Secretary',28550,'S','M','06-JUN- 85',4,440449448); 29 INSERT INTO EMPLOYEE VALUES (771772773,'Mary','C',null,'Richardson','Manager',64320,'S','F','05-MAY- 57',5,null); 30 INSERT INTO EMPLOYEE VALUES (717273747,'Keith','D',null,'Jones','Engineer',54320,'S','M','04-APR- 61',5,771772773); 31 INSERT INTO EMPLOYEE VALUES (656463626,'Kenneth','E',null,'Sudan','Engineer',53210,'S','M','03-MAR- 63',5,717273747); 32 INSERT INTO EMPLOYEE VALUES (565758595,'Larry','F',null,'Lawler','Technician',49870,'S','M','02-FEB- 71',5,717273747); 33 INSERT INTO EMPLOYEE VALUES (505958577,'Laura','G',null,'Tedesco','Technician',48760,'S','F','01-JAN- 73',5,717273747); 34 INSERT INTO EMPLOYEE VALUES (454647484,'Lisa','H','Collins','Ruby','Secretary',39870,'H','F','24-JUN- 82',5,717273747); 35* INSERT INTO EMPLOYEE VALUES (932184567,'Jim','I',null,'Aisner','Secretary',38760,'H','M','23-AUG- DCIS850-doylet Page 19

83',5,717273747); 36 SQL> start fillEmployee;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get updateDepartment; 1 UPDATE DEPARTMENT SET dept_mgr_ssn = 123456789 WHERE dept_number = 1; 2 UPDATE DEPARTMENT SET dept_mgr_ssn = 182838485 WHERE dept_number = 2; 3 UPDATE DEPARTMENT SET dept_mgr_ssn = 321098678 WHERE dept_number = 3; 4 UPDATE DEPARTMENT SET dept_mgr_ssn = 061928473 WHERE dept_number = 4; 5* UPDATE DEPARTMENT SET dept_mgr_ssn = 771772773 WHERE dept_number = 5;

SQL> start updateDepartment;

1 row updated. 1 row updated. 1 row updated. 1 row updated. 1 row updated.

SQL> get fillLocation; 1 INSERT INTO LOCATION VALUES (1,'Davie'); 2 INSERT INTO LOCATION VALUES (2,'Miami'); 3 INSERT INTO LOCATION VALUES (3,'Sunrise'); 4 INSERT INTO LOCATION VALUES (4,'New York'); 5 INSERT INTO LOCATION VALUES (5,'Newark'); 6* INSERT INTO LOCATION VALUES (3,'London'); DCIS850-doylet Page 20

SQL> start fillLocation;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillProject; 1 INSERT INTO PROJECT VALUES (1,'Project One',656463626,5); 2 INSERT INTO PROJECT VALUES (2,'Project Two',440449448,4); 3 INSERT INTO PROJECT VALUES (3,'Project Three',220330440,1); 4 INSERT INTO PROJECT VALUES (4,'Project Four',273747576,2); 5 INSERT INTO PROJECT VALUES (5,'Project Five',919293949,3); 6 INSERT INTO PROJECT VALUES (6,'Project Six',919293949,3); 7* INSERT INTO PROJECT VALUES (7,'Project Seven',919293949,3);

SQL> start fillProject;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillWorksOn; 1 INSERT INTO WORKS_ON VALUES (123456789,1,1); 2 INSERT INTO WORKS_ON VALUES (987654321,2,2); 3 INSERT INTO WORKS_ON VALUES (543219876,3,3); 4 INSERT INTO WORKS_ON VALUES (918273645,4,4); 5 INSERT INTO WORKS_ON VALUES (098765432,5,5); 6 INSERT INTO WORKS_ON VALUES (010203040,1,6); 7 INSERT INTO WORKS_ON VALUES (919293949,2,7); 8 INSERT INTO WORKS_ON VALUES (182838485,3,8); 9 INSERT INTO WORKS_ON VALUES (273747576,4,9); 10 INSERT INTO WORKS_ON VALUES (564636261,5,10); 11 INSERT INTO WORKS_ON VALUES (908070605,1,11); 12 INSERT INTO WORKS_ON VALUES (403020109,2,12); 13 INSERT INTO WORKS_ON VALUES (101918171,3,13); 14 INSERT INTO WORKS_ON VALUES (292827262,4,14); 15 INSERT INTO WORKS_ON VALUES (182838485,7,8); 16 INSERT INTO WORKS_ON VALUES (273747576,7,9); 17 INSERT INTO WORKS_ON VALUES (564636261,7,10); 18 INSERT INTO WORKS_ON VALUES (908070605,7,11); 19 INSERT INTO WORKS_ON VALUES (403020109,7,12); 20 INSERT INTO WORKS_ON VALUES (101918171,7,13); 21 INSERT INTO WORKS_ON VALUES (292827262,7,14); 22 INSERT INTO WORKS_ON VALUES (321098678,5,15); 23 INSERT INTO WORKS_ON VALUES (110220330,1,16); 24 INSERT INTO WORKS_ON VALUES (220330440,2,17); 25 INSERT INTO WORKS_ON VALUES (400300200,3,18); 26 INSERT INTO WORKS_ON VALUES (505958575,4,19); 27 INSERT INTO WORKS_ON VALUES (483920756,5,1); 28 INSERT INTO WORKS_ON VALUES (928372891,1,2); 29 INSERT INTO WORKS_ON VALUES (061928473,2,3); 30 INSERT INTO WORKS_ON VALUES (551552553,3,4); 31 INSERT INTO WORKS_ON VALUES (440449448,4,5); 32 INSERT INTO WORKS_ON VALUES (334335336,5,6); 33 INSERT INTO WORKS_ON VALUES (123321123,1,7); 34 INSERT INTO WORKS_ON VALUES (987789987,2,8); DCIS850-doylet Page 21

35 INSERT INTO WORKS_ON VALUES (768594032,3,9); 36 INSERT INTO WORKS_ON VALUES (061928473,6,3); 37 INSERT INTO WORKS_ON VALUES (551552553,6,4); 38 INSERT INTO WORKS_ON VALUES (440449448,6,5); 39 INSERT INTO WORKS_ON VALUES (334335336,6,6); 40 INSERT INTO WORKS_ON VALUES (123321123,6,7); 41 INSERT INTO WORKS_ON VALUES (987789987,6,8); 42 INSERT INTO WORKS_ON VALUES (768594032,6,9); 43 INSERT INTO WORKS_ON VALUES (771772773,4,10); 44 INSERT INTO WORKS_ON VALUES (717273747,5,11); 45 INSERT INTO WORKS_ON VALUES (656463626,1,12); 46 INSERT INTO WORKS_ON VALUES (565758595,2,13); 47 INSERT INTO WORKS_ON VALUES (505958575,3,14); 48 INSERT INTO WORKS_ON VALUES (454647484,4,15); 49* INSERT INTO WORKS_ON VALUES (932184567,5,16); 50 SQL> start fillWorksOn;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. DCIS850-doylet Page 22

1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillPart; 1 INSERT INTO PART VALUES (1,'Reading Tool','blinders keeper','orange',5,'Michigan'); 2 INSERT INTO PART VALUES (2,'Magnifier','round glass',null,0.5,'Luxemburg'); 3 INSERT INTO PART VALUES (3,'Handle','plastic','blue',0.32,'Topeka'); 4 INSERT INTO PART VALUES (4,'Tool Chest','organizer for all the tools available','yellow',21,'Ontario'); 5 INSERT INTO PART VALUES (5,'Writing Tool','writers blessing','red',8,'Little Rock'); 6* INSERT INTO PART VALUES (6,'Eraser',null,'brown',0.01,'Beigin');

SQL> start fillPart;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillSubpartOf; 1 INSERT INTO SUBPART_OF VALUES (1,2); 2 INSERT INTO SUBPART_OF VALUES (1,3); 3 INSERT INTO SUBPART_OF VALUES (4,1); 4 INSERT INTO SUBPART_OF VALUES (4,5); 5* INSERT INTO SUBPART_OF VALUES (5,6);

SQL> start fillSubpartOf;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillUses; 1 INSERT INTO USES VALUES (1,6); 2 INSERT INTO USES VALUES (2,5); 3 INSERT INTO USES VALUES (3,4); 4 INSERT INTO USES VALUES (4,3); 5 INSERT INTO USES VALUES (5,2); 6 INSERT INTO USES VALUES (1,1); 7 INSERT INTO USES VALUES (2,6); 8 INSERT INTO USES VALUES (3,5); 9 INSERT INTO USES VALUES (4,4); 10 INSERT INTO USES VALUES (5,3); 11 INSERT INTO USES VALUES (1,2); 12 INSERT INTO USES VALUES (2,2); 13 INSERT INTO USES VALUES (3,2); 14 INSERT INTO USES VALUES (4,2); 15 INSERT INTO USES VALUES (6,2); 16* INSERT INTO USES VALUES (7,2);

SQL> start fillUses;

1 row created. 1 row created. DCIS850-doylet Page 23

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillTelephone; 1 INSERT INTO TELEPHONE VALUES (123456789,'1234456','home'); 2 INSERT INTO TELEPHONE VALUES (987654321,'345.4322334','office'); 3 INSERT INTO TELEPHONE VALUES (543219876,'(564)234-4435','cel'); 4 INSERT INTO TELEPHONE VALUES (918273645,'344.435-8876','pager'); 5 INSERT INTO TELEPHONE VALUES (098765432,'(213) 332-1123','home'); 6 INSERT INTO TELEPHONE VALUES (010203040,'5463721','office'); 7 INSERT INTO TELEPHONE VALUES (919293949,'987-2345','cel'); 8 INSERT INTO TELEPHONE VALUES (182838485,'(234)567-8901','pager'); 9 INSERT INTO TELEPHONE VALUES (273747576,'9876543','home'); 10 INSERT INTO TELEPHONE VALUES (564636261,'123123234','office'); 11 INSERT INTO TELEPHONE VALUES (908070605,'changing','cel'); 12 INSERT INTO TELEPHONE VALUES (403020109,'83848212','pager'); 13 INSERT INTO TELEPHONE VALUES (101918171,'(342)567-1234','fax'); 14 INSERT INTO TELEPHONE VALUES (292827262,'(134)8172374','call back'); 15 INSERT INTO TELEPHONE VALUES (321098678,'pending','home'); 16 INSERT INTO TELEPHONE VALUES (110220330,'8273817','office'); 17 INSERT INTO TELEPHONE VALUES (220330440,'333-1234','cel'); 18 INSERT INTO TELEPHONE VALUES (400300200,'747-1148',''); 19 INSERT INTO TELEPHONE VALUES (505958575,'982-3291','pager'); 20 INSERT INTO TELEPHONE VALUES (483920756,'555-1212','fax'); 21 INSERT INTO TELEPHONE VALUES (928372891,'9203928','call back'); 22 INSERT INTO TELEPHONE VALUES (061928473,'777-1521','fax back'); 23 INSERT INTO TELEPHONE VALUES (551552553,'666-2343','help line'); 24 INSERT INTO TELEPHONE VALUES (440449448,'555-3232','emergency'); 25 INSERT INTO TELEPHONE VALUES (334335336,'444-6765','home'); 26 INSERT INTO TELEPHONE VALUES (123321123,'333-7654','cel'); 27 INSERT INTO TELEPHONE VALUES (987789987,'222-9807','pager'); 28 INSERT INTO TELEPHONE VALUES (768594032,'111-7659','office'); 29 INSERT INTO TELEPHONE VALUES (771772773,'(212) 324-0324','office'); 30 INSERT INTO TELEPHONE VALUES (717273747,'(718) 432-9944','pager'); 31 INSERT INTO TELEPHONE VALUES (656463626,'(513) 777-4352','cel'); 32 INSERT INTO TELEPHONE VALUES (565758595,'(312) 493-8752','home'); 33 INSERT INTO TELEPHONE VALUES (505958575,'(414) 823-1592','emergency'); 34 INSERT INTO TELEPHONE VALUES (454647484,'(515) 726-5536','help line'); 35 INSERT INTO TELEPHONE VALUES (932184567,'(627) 453-8227','fax back'); 36 INSERT INTO TELEPHONE VALUES (771772773,'467','extension'); 37 INSERT INTO TELEPHONE VALUES (717273747,'356','extension'); 38 INSERT INTO TELEPHONE VALUES (656463626,'245','extension'); 39 INSERT INTO TELEPHONE VALUES (565758595,'134','extension'); 40 INSERT INTO TELEPHONE VALUES (505958575,'890','extension'); 41 INSERT INTO TELEPHONE VALUES (454647484,'789','extension'); 42 INSERT INTO TELEPHONE VALUES (932184567,'678','extension'); 43 INSERT INTO TELEPHONE VALUES (656463626,'567','extension'); 44 INSERT INTO TELEPHONE VALUES (565758595,'456','extension'); 45 INSERT INTO TELEPHONE VALUES (505958575,'345','extension'); 46 INSERT INTO TELEPHONE VALUES (454647484,'234','extension'); 47* INSERT INTO TELEPHONE VALUES (932184567,'123','extension'); DCIS850-doylet Page 24

48 SQL> start fillTelephone;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillAddress; 1 INSERT INTO ADDRESS VALUES (123456789,'home','2100 N. Australian Av.','','West Palm Beach',33407); 2 INSERT INTO ADDRESS VALUES (987654321,'home','12003 Mirtle Oak Ct.','','Sunrise',33411); 3 INSERT INTO ADDRESS VALUES (543219876,'home','143 Windsor Ln.','','Greenacres',33414); 4 INSERT INTO ADDRESS VALUES (918273645,'home','198 Bracken Wood Rd.','','North Palm Beach',33410); 5 INSERT INTO ADDRESS VALUES (098765432,'home','127 Dimbar Rd','','Palm Beach',33413); 6 INSERT INTO ADDRESS VALUES (010203040,'home','825 New Providence DCIS850-doylet Page 25

Rd.','','West Palm Beach',33401); 7 INSERT INTO ADDRESS VALUES (919293949,'home','1159 Presley Blvd.','Second Floor','WPB',33477); 8 INSERT INTO ADDRESS VALUES (182838485,'home','4102 Community Dr.','','Miami',12345); 9 INSERT INTO ADDRESS VALUES (273747576,'home','7213 Prescott Ln.','','Coral Gables',54321); 10 INSERT INTO ADDRESS VALUES (564636261,'home','221 A1A Highway.','','Homestead',12321); 11 INSERT INTO ADDRESS VALUES (908070605,'home','4900 Sand Dune Ctr.','','Miami',23454); 12 INSERT INTO ADDRESS VALUES (403020109,'home','6156 Willougnby Cir.','','Key West',34565); 13 INSERT INTO ADDRESS VALUES (101918171,'home','661 Springdale Cir','','South Beach',45676); 14 INSERT INTO ADDRESS VALUES (292827262,'home','2345 Sopranos Blvd.','3rd floor','Miami',56787); 15 INSERT INTO ADDRESS VALUES (321098678,'home','23 Martirs Way Drive','','Sunrise',67898); 16 INSERT INTO ADDRESS VALUES (110220330,'home','432 Okeecho Court','','Sunrise',78909); 17 INSERT INTO ADDRESS VALUES (220330440,'home','234 Bienvenido Hwy.','','Sunrise',13245); 18 INSERT INTO ADDRESS VALUES (400300200,'home','4500 Commons Circle','','Sunrise',24356); 19 INSERT INTO ADDRESS VALUES (505958575,'home','17 Playground Ranch','','Sunrise',35467); 20 INSERT INTO ADDRESS VALUES (483920756,'home','16 SE 13 St.','4th floor, apt. 4','Sunrise',46578); 21 INSERT INTO ADDRESS VALUES (928372891,'home','1032 Osprey Point Circle','','Sunrise',57689); 22 INSERT INTO ADDRESS VALUES (061928473,'home','2500 Quantum Lakes Dr.','','New York',68790); 23 INSERT INTO ADDRESS VALUES (551552553,'home','2247 Palm Beach Lakes Blvd.','Suite 220','New York',91827); 24 INSERT INTO ADDRESS VALUES (440449448,'home','7655 Enterprise Drive','Suite A1','New York',81726); 25 INSERT INTO ADDRESS VALUES (334335336,'home','1021 State Road 7','','New York',71625); 26 INSERT INTO ADDRESS VALUES (123321123,'home','2329 Ninth Street North','','New York',61524); 27 INSERT INTO ADDRESS VALUES (987789987,'home','4075 Tamiami Trail North','','New York',51413); 28 INSERT INTO ADDRESS VALUES (768594032,'home','3870 Estero Blvd.','','New York',40494); 29 INSERT INTO ADDRESS VALUES (771772773,'home','6689 West Indiana Road','','Newark',30393); 30 INSERT INTO ADDRESS VALUES (717273747,'home','731 Village Boulevard','Suite 108','Newark',20292); 31 INSERT INTO ADDRESS VALUES (656463626,'home','817 Lake Avenue','','Newark',10191); 32 INSERT INTO ADDRESS VALUES (565758595,'home','606 Lake Avenue','','Newark',12092); 33 INSERT INTO ADDRESS VALUES (505958577,'home','10107 Southern Blvd.','','Newark',23092); 34 INSERT INTO ADDRESS VALUES (454647484,'home','3044 S. Military Trail','','Newark',34093); 35 INSERT INTO ADDRESS VALUES (932184567,'home','3087 Forest Hill Blvd.','','Newark',45094); 36 INSERT INTO ADDRESS VALUES (771772773,'permanent','20 NW Valencia Avenue','','Dayton',12309); 37 INSERT INTO ADDRESS VALUES (717273747,'permanent','2282 Congress Ave.','','Chicago',23409); DCIS850-doylet Page 26

38 INSERT INTO ADDRESS VALUES (656463626,'permanent','566 Mississipy Gardens','','Denver',23498); 39 INSERT INTO ADDRESS VALUES (565758595,'permanent','3020 Gagliano Highway','','Kansas',23487); 40 INSERT INTO ADDRESS VALUES (505958575,'permanent','800 Royal Palm Blvd.','','Orlando',12387); 41 INSERT INTO ADDRESS VALUES (454647484,'permanent','3585 Boutwell Rd.','','Ocala',21376); 42 INSERT INTO ADDRESS VALUES (932184567,'permanent','54 Buckanans Way','','Paris',54398); 43 INSERT INTO ADDRESS VALUES (656463626,'vacation spot','3365 Lake Worth Rd.','','Kremlin',45399); 44 INSERT INTO ADDRESS VALUES (565758595,'vacation spot','1801 Palisades Parkway','','Quito',00000); 45 INSERT INTO ADDRESS VALUES (505958575,'vacation spot','245 Toney Penna Dr.','','Babilonia',00000); 46 INSERT INTO ADDRESS VALUES (454647484,'vacation spot','333 Southern Boulevard','','Ibarra',00000); 47* INSERT INTO ADDRESS VALUES (932184567,'vacation spot','12189 US Highway 1','','San Jose',00000); 48 SQL> start fillAddress;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. DCIS850-doylet Page 27

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillDependent; 1 INSERT INTO DEPENDENT VALUES (123456789,'Maria','28-JUN- 90','F','daughter'); 2 INSERT INTO DEPENDENT VALUES (987654321,'Sonia','27-FEB- 91','F','daughter'); 3 INSERT INTO DEPENDENT VALUES (543219876,'Pablo','26-MAR-92','M','son'); 4 INSERT INTO DEPENDENT VALUES (918273645,'Eulogio','25-APR- 93','M','son'); 5 INSERT INTO DEPENDENT VALUES (098765432,'Francis','24-MAY- 94','F','daughter'); 6 INSERT INTO DEPENDENT VALUES (123456789,'Teo','23-JUN-95','M','son'); 7 INSERT INTO DEPENDENT VALUES (987654321,'Virgil','22-JUL-96','M','son'); 8 INSERT INTO DEPENDENT VALUES (543219876,'Demostenes','21-AUG- 97','M','son'); 9 INSERT INTO DEPENDENT VALUES (182838485,'Trisha','20-SEP- 98','F','daughter'); 10 INSERT INTO DEPENDENT VALUES (273747576,'Penny','19-OCT- 99','F','daughter'); 11 INSERT INTO DEPENDENT VALUES (564636261,'Tania','18-NOV- 00','F','daughter'); 12 INSERT INTO DEPENDENT VALUES (908070605,'Dora','17-DEC- 01','F','daughter'); 13 INSERT INTO DEPENDENT VALUES (403020109,'Paul','16-JUN-02','M','son'); 14 INSERT INTO DEPENDENT VALUES (101918171,'Bob','15-FEB-03','M','son'); 15 INSERT INTO DEPENDENT VALUES (101918171,'Sergio','14-MAR-04','M','son'); 16 INSERT INTO DEPENDENT VALUES (292827262,'Tania','13-APR- 03','F','daughter'); 17 INSERT INTO DEPENDENT VALUES (321098678,'Tony','12-MAY-02','M','son'); 18 INSERT INTO DEPENDENT VALUES (110220330,'Tony','11-JUN-01','M','son'); 19 INSERT INTO DEPENDENT VALUES (220330440,'George','10-JUL-00','M','son'); 20 INSERT INTO DEPENDENT VALUES (400300200,'Gina','09-AUG- 99','F','daughter'); 21 INSERT INTO DEPENDENT VALUES (505958575,'Prince','08-SEP-98','M','son'); 22 INSERT INTO DEPENDENT VALUES (220330440,'Zhijian','07-OCT- 97','F','daughter'); 23 INSERT INTO DEPENDENT VALUES (400300200,'Tay','06-NOV- 96','F','daughter'); 24 INSERT INTO DEPENDENT VALUES (505958575,'Federico','05-DEC- 95','M','son'); 25 INSERT INTO DEPENDENT VALUES (061928473,'Charlie','04-JAN- 94','M','son'); 26 INSERT INTO DEPENDENT VALUES (551552553,'Hector','03-FEB-93','M','son'); 27 INSERT INTO DEPENDENT VALUES (440449448,'Italo','02-MAR-92','M','son'); 28 INSERT INTO DEPENDENT VALUES (334335336,'James','01-APR-91','M','son'); 29 INSERT INTO DEPENDENT VALUES (334335336,'Jessica','02-MAY- 90','F','daughter'); 30 INSERT INTO DEPENDENT VALUES (123321123,'Olivo','03-JUN- 91','F','daughter'); 31 INSERT INTO DEPENDENT VALUES (987789987,'Kevin','04-JUL-92','M','son'); 32 INSERT INTO DEPENDENT VALUES (768594032,'Klever','05-AUG-93','M','son'); 33 INSERT INTO DEPENDENT VALUES (771772773,'Laura','06-SEP- 94','F','daughter'); 34 INSERT INTO DEPENDENT VALUES (717273747,'Nancy','07-OCT- 95','F','daughter'); 35 INSERT INTO DEPENDENT VALUES (717273747,'Oscar','08-NOV-96','M','son'); DCIS850-doylet Page 28

36 INSERT INTO DEPENDENT VALUES (656463626,'Patrick','09-DEC- 97','M','son'); 37 INSERT INTO DEPENDENT VALUES (656463626,'Patricia','10-NOV- 98','F','daughter'); 38 INSERT INTO DEPENDENT VALUES (932184567,'Ronald','11-OCT-99','M','son'); 39* INSERT INTO DEPENDENT VALUES (932184567,'Sara','12-SEP- 00','F','daughter');

SQL> start fillDependent;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> get fillSupplier; 1 INSERT INTO SUPPLIER VALUES (1,'FirstSupplier','warning','Lagos'); 2 INSERT INTO SUPPLIER VALUES (12,'AmeriSupplies','good','Boston'); 3 INSERT INTO SUPPLIER VALUES (23,'EuroSupplies','good','Paris'); 4 INSERT INTO SUPPLIER VALUES (34,'AfroSupplies','warning','Esmeraldas'); 5 INSERT INTO SUPPLIER VALUES (45,'AsianSupplies','pending','Tokio'); 6* INSERT INTO SUPPLIER VALUES (56,'PrimeSupplies','good','London');

SQL> start fillSupplier;

1 row created. 1 row created. 1 row created. DCIS850-doylet Page 29

1 row created. 1 row created. 1 row created.

SQL> get fillSuppliedBy; 1 INSERT INTO SUPPLIED_BY VALUES (1,12,12500); 2 INSERT INTO SUPPLIED_BY VALUES (1,23,1345); 3 INSERT INTO SUPPLIED_BY VALUES (1,34,23412); 4 INSERT INTO SUPPLIED_BY VALUES (1,45,4000); 5 INSERT INTO SUPPLIED_BY VALUES (2,56,43211); 6 INSERT INTO SUPPLIED_BY VALUES (2,45,453576); 7 INSERT INTO SUPPLIED_BY VALUES (2,34,555); 8 INSERT INTO SUPPLIED_BY VALUES (3,23,666); 9 INSERT INTO SUPPLIED_BY VALUES (3,12,777); 10 INSERT INTO SUPPLIED_BY VALUES (4,23,888); 11 INSERT INTO SUPPLIED_BY VALUES (5,34,999); 12 INSERT INTO SUPPLIED_BY VALUES (5,45,1234); 13 INSERT INTO SUPPLIED_BY VALUES (6,56,2345); 14 INSERT INTO SUPPLIED_BY VALUES (6,12,3456); 15 INSERT INTO SUPPLIED_BY VALUES (6,23,56789); 16 INSERT INTO SUPPLIED_BY VALUES (2,23,56789); 17 INSERT INTO SUPPLIED_BY VALUES (5,23,56789); 18 INSERT INTO SUPPLIED_BY VALUES (1,1,4000); 19 INSERT INTO SUPPLIED_BY VALUES (2,1,400); 20 INSERT INTO SUPPLIED_BY VALUES (4,1,40); 21* INSERT INTO SUPPLIED_BY VALUES (6,1,4);

SQL> start fillSuppliedBy;

1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created. 1 row created.

SQL> spool off; DCIS850-doylet Page 30

7. Implement the given queries Implement the given queries in ORACLE/SQL*PLUS.

1. List all the relations in the database.

SQL> get fq1; 1 PROMPT; 2 PROMPT Relations in this Database; 3* SELECT * FROM tab WHERE tabtype = 'TABLE';

SQL> start fq1;

Relations in this Database

TNAME TABTYPE CLUSTERID ------ADDRESS TABLE DEPARTMENT TABLE DEPENDENT TABLE EMPLOYEE TABLE LOCATION TABLE PART TABLE PROJECT TABLE SUBPART_OF TABLE SUPPLIED_BY TABLE SUPPLIER TABLE TELEPHONE TABLE

TNAME TABTYPE CLUSTERID ------USES TABLE WORKS_ON TABLE

13 rows selected.

2. List all the attributes and type definitions for each table.

SQL> get fq2; 1 PROMPT; 2 PROMPT Attributes and Type definitions for table DEPARTMENT; 3 PROMPT; 4 DESCRIBE DEPARTMENT; 5 PROMPT; 6 PROMPT Attributes and Type definitions for table LOCATION; 7 PROMPT; 8 DESCRIBE LOCATION; 9 PROMPT; 10 PROMPT Attributes and Type definitions for table PROJECT; 11 PROMPT; 12 DESCRIBE PROJECT; 13 PROMPT; 14 PROMPT Attributes and Type definitions for table WORKS_ON; 15 PROMPT; 16 DESCRIBE WORKS_ON; 17 PROMPT; 18 PROMPT Attributes and Type definitions for table PART; 19 PROMPT; 20 DESCRIBE PART; 21 PROMPT; DCIS850-doylet Page 31

22 PROMPT Attributes and Type definitions for table SUBPART_OF; 23 PROMPT; 24 DESCRIBE SUBPART_OF; 25 PROMPT; 26 PROMPT Attributes and Type definitions for table USES; 27 PROMPT; 28 DESCRIBE USES; 29 PROMPT; 30 PROMPT Attributes and Type definitions for table SUPPLIES_BY; 31 PROMPT; 32 DESCRIBE SUPPLIED_BY; 33 PROMPT; 34 PROMPT Attributes and Type definitions for table EMPLOYEE; 35 PROMPT; 36 DESCRIBE EMPLOYEE; 37 PROMPT; 38 PROMPT Attributes and Type definitions for table TELEPHONE; 39 PROMPT; 40 DESCRIBE TELEPHONE; 41 PROMPT; 42 PROMPT Attributes and Type definitions for table ADDRESS; 43 PROMPT; 44 DESCRIBE ADDRESS; 45 PROMPT; 46 PROMPT Attributes and Type definitions for table DEPENDENT; 47 PROMPT; 48 DESCRIBE DEPENDENT; 49 PROMPT; 50 PROMPT Attributes and Type definitions for table SUPPLIER; 51 PROMPT; 52* DESCRIBE SUPPLIER;

SQL> start fq2;

Attributes and Type definitions for table DEPARTMENT

Name Null? Type ------DEPT_NAME NOT NULL VARCHAR2(50) DEPT_NUMBER NOT NULL NUMBER(38) DEPT_MGR_SSN NUMBER(38) DEPT_MGR_START_DT DATE

Attributes and Type definitions for table LOCATION

Name Null? Type ------LOC_DEPT_NUM NOT NULL NUMBER(38) LOC_CITY NOT NULL VARCHAR2(50)

Attributes and Type definitions for table PROJECT

Name Null? Type ------PROJ_NUM NOT NULL NUMBER(38) PROJ_NAME NOT NULL VARCHAR2(50) PROJ_MGR_SSN NUMBER(38) PROJ_DEPT_NUM NOT NULL NUMBER(38)

Attributes and Type definitions for table WORKS_ON DCIS850-doylet Page 32

Name Null? Type ------WO_SSN NOT NULL NUMBER(38) WO_PROJ_NUM NOT NULL NUMBER(38) WEEK_HOURS NUMBER(5,2)

Attributes and Type definitions for table PART

Name Null? Type ------PART_NUM NOT NULL NUMBER(38) PART_NAME NOT NULL VARCHAR2(50) PART_DESC VARCHAR2(50) PART_COLOR VARCHAR2(20) PART_WEIGHT NUMBER(38) PART_CITY NOT NULL VARCHAR2(30)

Attributes and Type definitions for table SUBPART_OF

Name Null? Type ------SO_PART NOT NULL NUMBER(38) SO_SUBPART NOT NULL NUMBER(38)

Attributes and Type definitions for table USES

Name Null? Type ------USE_PROJECT NOT NULL NUMBER(38) USE_PART NOT NULL NUMBER(38)

Attributes and Type definitions for table SUPPLIES_BY

Name Null? Type ------SB_PART NOT NULL NUMBER(38) SB_SUPPLIER NOT NULL NUMBER(38) QUANTITY NUMBER(38)

Attributes and Type definitions for table EMPLOYEE

Name Null? Type ------EMP_SSN NOT NULL NUMBER(38) EMP_NAME_FIRST NOT NULL VARCHAR2(50) EMP_NAME_MI CHAR(1) EMP_NAME_MAIDEN VARCHAR2(50) EMP_NAME_LAST NOT NULL VARCHAR2(50) EMP_JOBTYPE VARCHAR2(10) EMP_SALARY NUMBER(38) EMP_SAL_HOUR VARCHAR2(10) EMP_SEX CHAR(1) EMP_BIRTHDATE DATE EMP_DEPT_NUMBER NUMBER(38) EMP_SUPERVISOR_SSN NUMBER(38) DCIS850-doylet Page 33

Attributes and Type definitions for table TELEPHONE

Name Null? Type ------TEL_SSN NOT NULL NUMBER(38) TEL_NUM NOT NULL VARCHAR2(20) TEL_TYPE VARCHAR2(50)

Attributes and Type definitions for table ADDRESS

Name Null? Type ------ADD_SSN NOT NULL NUMBER(38) ADD_TYPE NOT NULL VARCHAR2(50) ADD_LINE1 NOT NULL VARCHAR2(50) ADD_LINE2 VARCHAR2(50) ADD_CITY NOT NULL VARCHAR2(50) ADD_ZIP NOT NULL VARCHAR2(10)

Attributes and Type definitions for table DEPENDENT

Name Null? Type ------DEP_EMP_SSN NOT NULL NUMBER(38) DEP_NAME NOT NULL VARCHAR2(50) DEP_BIRTHDATE NOT NULL DATE DEP_SEX VARCHAR2(10) DEP_RELATION VARCHAR2(50)

Attributes and Type definitions for table SUPPLIER

Name Null? Type ------SUP_NUM NOT NULL NUMBER(38) SUP_NAME NOT NULL VARCHAR2(50) SUP_STATUS VARCHAR2(30) SUP_CITY NOT NULL VARCHAR2(30)

3. List all the tuples in each table.

SQL> get fq3; 1 PROMPT; 2 PROMPT Adjusting column formats to improve display... 3 COLUMN emp_name_first FORMAT A15; 4 COLUMN emp_name_maiden FORMAT A15; 5 COLUMN emp_name_last FORMAT A15; 6 COLUMN dept_name FORMAT A20; 7 COLUMN proj_name FORMAT A20; 8 COLUMN part_name FORMAT A15; 9 COLUMN part_desc FORMAT A20; 10 COLUMN part_city FORMAT A15; 11 COLUMN part_color FORMAT A10; 12 COLUMN part_num FORMAT 99999999; 13 COLUMN tel_type FORMAT A15; 14 COLUMN add_type FORMAT A9; 15 COLUMN add_line1 FORMAT A21; 16 COLUMN add_line2 FORMAT A9; 17 COLUMN add_city FORMAT A16; DCIS850-doylet Page 34

18 COLUMN dep_name FORMAT A15; 19 COLUMN dep_relation FORMAT A12; 20 COLUMN sup_name FORMAT A15; 21 COLUMN sup_status FORMAT A10; 22 PROMPT; 23 PROMPT Tuples in table DEPARTMENT; 24 SELECT * FROM DEPARTMENT; 25 PROMPT Tuples in table LOCATION; 26 SELECT * FROM LOCATION; 27 PROMPT Tuples in table PROJECT; 28 SELECT * FROM PROJECT; 29 PROMPT Tuples in table WORKS_ON; 30 SELECT * FROM WORKS_ON; 31 PROMPT Tuples in table PART; 32 SELECT * FROM PART; 33 PROMPT Tuples in table SUBPART_OF; 34 SELECT * FROM SUBPART_OF; 35 PROMPT Tuples in table USES; 36 SELECT * FROM USES; 37 PROMPT Tuples in table SUPPLIED_BY; 38 SELECT * FROM SUPPLIED_BY; 39 PROMPT Tuples in table EMPLOYEE; 40 SELECT * FROM EMPLOYEE; 41 PROMPT Tuples in table TELEPHONE; 42 SELECT * FROM TELEPHONE; 43 PROMPT Tuples in table ADDRESS; 44 SELECT * FROM ADDRESS; 45 PROMPT Tuples in table DEPENDENT; 46 SELECT * FROM DEPENDENT; 47 PROMPT Tuples in table SUPPLIER; 48* SELECT * FROM SUPPLIER;

SQL> start fq3;

Adjusting column formats to improve display...

Tuples in table DEPARTMENT

DEPT_NAME DEPT_NUMBER DEPT_MGR_SSN DEPT_MGR_ ------Accounting 1 123456789 20-JUN-78 Management 2 182838485 15-NOV-80 Personnel 3 321098678 Marketing 4 61928473 Human Resources 5 771772773

Tuples in table LOCATION

LOC_DEPT_NUM LOC_CITY ------1 Davie 2 Miami 3 Sunrise 4 New York 5 Newark 3 London

6 rows selected.

Tuples in table PROJECT

PROJ_NUM PROJ_NAME PROJ_MGR_SSN PROJ_DEPT_NUM ------DCIS850-doylet Page 35

1 Project One 656463626 5 2 Project Two 440449448 4 3 Project Three 220330440 1 4 Project Four 273747576 2 5 Project Five 919293949 3 6 Project Six 919293949 3 7 Project Seven 919293949 3

7 rows selected.

Tuples in table WORKS_ON

WO_SSN WO_PROJ_NUM WEEK_HOURS ------123456789 1 1 987654321 2 2 543219876 3 3 918273645 4 4 98765432 5 5 10203040 1 6 919293949 2 7 182838485 3 8 273747576 4 9 564636261 5 10 908070605 1 11

WO_SSN WO_PROJ_NUM WEEK_HOURS ------403020109 2 12 101918171 3 13 292827262 4 14 182838485 7 8 273747576 7 9 564636261 7 10 908070605 7 11 403020109 7 12 101918171 7 13 292827262 7 14 321098678 5 15

WO_SSN WO_PROJ_NUM WEEK_HOURS ------110220330 1 16 220330440 2 17 400300200 3 18 505958575 4 19 483920756 5 1 928372891 1 2 61928473 2 3 551552553 3 4 440449448 4 5 334335336 5 6 123321123 1 7

WO_SSN WO_PROJ_NUM WEEK_HOURS ------987789987 2 8 768594032 3 9 61928473 6 3 551552553 6 4 440449448 6 5 334335336 6 6 123321123 6 7 DCIS850-doylet Page 36

987789987 6 8 768594032 6 9 771772773 4 10 717273747 5 11

WO_SSN WO_PROJ_NUM WEEK_HOURS ------656463626 1 12 565758595 2 13 505958575 3 14 454647484 4 15 932184567 5 16

49 rows selected.

Tuples in table PART

PART_NUM PART_NAME PART_DESC PART_COLOR PART_WEIGHT ------PART_CITY ------1 Reading Tool blinders keeper orange 5 Michigan

2 Magnifier round glass 1 Luxemburg

3 Handle plastic blue 0 Topeka

PART_NUM PART_NAME PART_DESC PART_COLOR PART_WEIGHT ------PART_CITY ------4 Tool Chest organizer for all th yellow 21 e tools available Ontario

5 Writing Tool writers blessing red 8 Little Rock

6 Eraser brown 0 Beigin

PART_NUM PART_NAME PART_DESC PART_COLOR PART_WEIGHT ------PART_CITY ------

6 rows selected.

Tuples in table SUBPART_OF

SO_PART SO_SUBPART ------1 2 1 3 4 1 4 5 5 6 DCIS850-doylet Page 37

Tuples in table USES

USE_PROJECT USE_PART ------1 6 2 5 3 4 4 3 5 2 1 1 2 6 3 5 4 4 5 3 1 2

USE_PROJECT USE_PART ------2 2 3 2 4 2 6 2 7 2

16 rows selected.

Tuples in table SUPPLIED_BY

SB_PART SB_SUPPLIER QUANTITY ------1 12 12500 1 23 1345 1 34 23412 1 45 4000 2 56 43211 2 45 453576 2 34 555 3 23 666 3 12 777 4 23 888 5 34 999

SB_PART SB_SUPPLIER QUANTITY ------5 45 1234 6 56 2345 6 12 3456 6 23 56789 2 23 56789 5 23 56789 1 1 4000 2 1 400 4 1 40 6 1 4

21 rows selected.

Tuples in table EMPLOYEE

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------DCIS850-doylet Page 38

123456789 Edward F Kling Manager 75000 H M 13-DEC-58 1

543219876 Peter D Sucre Engineer 60000 S M 30-AUG-65 1 123456789

987654321 Ernest E De La Torre Technician 40000 S M 15-SEP-64 1 543219876

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------10203040 Irma A Landivar Torres Secretary 28000 H F 17-MAY-76 1 543219876

918273645 Francis C Terranova Carbo Secretary 30000 H F 02-FEB-74 1 987654321

98765432 Gladys B Davila Secretary 25000 H F 12-MAR-80 1 123456789

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------919293949 Anna G Barbas Lobos Technician 45000 S F 05-OCT-62 1 123456789

182838485 Dana H Thomas Manager 70000 S F 23-AUG-59 2

564636261 Carol J Crocker Terrell Engineer 43500 S F 10-APR-60 2 182838485

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------908070605 Jeffrey K Denny Engineer 42000 H M 14-JAN-63 2 182838485

273747576 John I Jasso Technician 35000 S M 05-JUL-66 2 564636261

403020109 Ashley L David Secretary 28500 H F 25-NOV-70 2 908070605

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------101918171 Sam M Ramseyer Technician 33000 S M 30-AUG-66 2 908070605

292827262 Brenda N Douglas Olive Secretary 25678 S F 22-OCT-72 2 564636261

321098678 Addiel O Millan Manager DCIS850-doylet Page 39

65000 S M 24-NOV-48 3

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------110220330 Ronald P Torrido Engineer 44530 S M 03-OCT-61 3 321098678

220330440 Estuardo Q Sanchez Technician 35440 H M 14-DEC-61 3 110220330

400300200 Frank R Imparato Technician 33420 H M 12-JAN-63 3 110220330

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------505958575 Dorothy S Hale Secretary 28500 H F 18-FEB-73 3 220330440

483920756 Eunice T Zurita Duran Secretary 27600 H F 29-MAR-75 3 110220330

928372891 Joyce U English Gamboa Secretary 26000 S F 21-APR-77 3 321098678

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------61928473 Monica V Okeefe Manager 62340 H F 12-DEC-55 4

551552553 Marie W Green Engineer 47890 H F 11-NOV-60 4 61928473

440449448 Linda X Ogus Engineer 45670 H F 10-OCT-65 4 61928473

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------334335336 Robert Y Mueller Technician 38540 S M 09-SEP-79 4 551552553

123321123 Roger Z Mekala Technician 34350 S M 08-AUG-75 4 551552553

987789987 Richard A Laux Secretary 29340 S M 07-JUL-80 4 440449448

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------DCIS850-doylet Page 40

768594032 Kevin B Jones Secretary 28550 S M 06-JUN-85 4 440449448

771772773 Mary C Richardson Manager 64320 S F 05-MAY-57 5

717273747 Keith D Jones Engineer 54320 S M 04-APR-61 5 771772773

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------656463626 Kenneth E Sudan Engineer 53210 S M 03-MAR-63 5 717273747

565758595 Larry F Lawler Technician 49870 S M 02-FEB-71 5 717273747

505958577 Laura G Tedesco Technician 48760 S F 01-JAN-73 5 717273747

EMP_SSN EMP_NAME_FIRST E EMP_NAME_MAIDEN EMP_NAME_LAST EMP_JOBTYP ------EMP_SALARY EMP_SAL_HO E EMP_BIRTH EMP_DEPT_NUMBER EMP_SUPERVISOR_SSN ------454647484 Lisa H Collins Ruby Secretary 39870 H F 24-JUN-82 5 717273747

932184567 Jim I Aisner Secretary 38760 H M 23-AUG-83 5 717273747

35 rows selected.

Tuples in table TELEPHONE

TEL_SSN TEL_NUM TEL_TYPE ------123456789 1234456 home 987654321 345.4322334 office 543219876 (564)234-4435 cel 918273645 344.435-8876 pager 98765432 (213) 332-1123 home 10203040 5463721 office 919293949 987-2345 cel 182838485 (234)567-8901 pager 273747576 9876543 home 564636261 123123234 office 908070605 changing cel

TEL_SSN TEL_NUM TEL_TYPE ------403020109 83848212 pager 101918171 (342)567-1234 fax 292827262 (134)8172374 call back 321098678 pending home 110220330 8273817 office 220330440 333-1234 cel 400300200 747-1148 505958575 982-3291 pager DCIS850-doylet Page 41

483920756 555-1212 fax 928372891 9203928 call back 61928473 777-1521 fax back

TEL_SSN TEL_NUM TEL_TYPE ------551552553 666-2343 help line 440449448 555-3232 emergency 334335336 444-6765 home 123321123 333-7654 cel 987789987 222-9807 pager 768594032 111-7659 office 771772773 (212) 324-0324 office 717273747 (718) 432-9944 pager 656463626 (513) 777-4352 cel 565758595 (312) 493-8752 home 505958575 (414) 823-1592 emergency

TEL_SSN TEL_NUM TEL_TYPE ------454647484 (515) 726-5536 help line 932184567 (627) 453-8227 fax back 771772773 467 extension 717273747 356 extension 656463626 245 extension 565758595 134 extension 505958575 890 extension 454647484 789 extension 932184567 678 extension 656463626 567 extension 565758595 456 extension

TEL_SSN TEL_NUM TEL_TYPE ------505958575 345 extension 454647484 234 extension 932184567 123 extension

47 rows selected.

Tuples in table ADDRESS

ADD_SSN ADD_TYPE ADD_LINE1 ADD_LINE2 ADD_CITY ADD_Z ------123456789 home 2100 N. Australian Av West Palm Beach 33407 .

987654321 home 12003 Mirtle Oak Ct. Sunrise 33411 543219876 home 143 Windsor Ln. Greenacres 33414 918273645 home 198 Bracken Wood Rd. North Palm Beach 33410 98765432 home 127 Dimbar Rd Palm Beach 33413 10203040 home 825 New Providence Rd West Palm Beach 33401 .

919293949 home 1159 Presley Blvd. Second Fl WPB 33477

ADD_SSN ADD_TYPE ADD_LINE1 ADD_LINE2 ADD_CITY ADD_Z ------oor

182838485 home 4102 Community Dr. Miami 12345 273747576 home 7213 Prescott Ln. Coral Gables 54321 564636261 home 221 A1A Highway. Homestead 12321 DCIS850-doylet Page 42

908070605 home 4900 Sand Dune Ctr. Miami 23454 403020109 home 6156 Willougnby Cir. Key West 34565 101918171 home 661 Springdale Cir South Beach 45676 292827262 home 2345 Sopranos Blvd. 3rd floor Miami 56787 321098678 home 23 Martirs Way Drive Sunrise 67898 110220330 home 432 Okeecho Court Sunrise 78909

ADD_SSN ADD_TYPE ADD_LINE1 ADD_LINE2 ADD_CITY ADD_Z ------220330440 home 234 Bienvenido Hwy. Sunrise 13245 400300200 home 4500 Commons Circle Sunrise 24356 505958575 home 17 Playground Ranch Sunrise 35467 483920756 home 16 SE 13 St. 4th floor Sunrise 46578 , apt. 4

928372891 home 1032 Osprey Point Cir Sunrise 57689 cle

61928473 home 2500 Quantum Lakes Dr New York 68790 .

ADD_SSN ADD_TYPE ADD_LINE1 ADD_LINE2 ADD_CITY ADD_Z ------

551552553 home 2247 Palm Beach Lakes Suite 220 New York 91827 Blvd.

440449448 home 7655 Enterprise Drive Suite A1 New York 81726 334335336 home 1021 State Road 7 New York 71625 123321123 home 2329 Ninth Street Nor New York 61524 th

987789987 home 4075 Tamiami Trail No New York 51413 rth

ADD_SSN ADD_TYPE ADD_LINE1 ADD_LINE2 ADD_CITY ADD_Z ------

768594032 home 3870 Estero Blvd. New York 40494 771772773 home 6689 West Indiana Roa Newark 30393 d

717273747 home 731 Village Boulevard Suite 108 Newark 20292 656463626 home 817 Lake Avenue Newark 10191 565758595 home 606 Lake Avenue Newark 12092 505958577 home 10107 Southern Blvd. Newark 23092 454647484 home 3044 S. Military Trai Newark 34093 l

ADD_SSN ADD_TYPE ADD_LINE1 ADD_LINE2 ADD_CITY ADD_Z ------

932184567 home 3087 Forest Hill Blvd Newark 45094 .

771772773 permanent 20 NW Valencia Avenue Dayton 12309 717273747 permanent 2282 Congress Ave. Chicago 23409 656463626 permanent 566 Mississipy Garden Denver 23498 s

565758595 permanent 3020 Gagliano Highway Kansas 23487 505958575 permanent 800 Royal Palm Blvd. Orlando 12387 DCIS850-doylet Page 43

ADD_SSN ADD_TYPE ADD_LINE1 ADD_LINE2 ADD_CITY ADD_Z ------454647484 permanent 3585 Boutwell Rd. Ocala 21376 932184567 permanent 54 Buckanans Way Paris 54398 656463626 vacation 3365 Lake Worth Rd. Kremlin 45399 spot

565758595 vacation 1801 Palisades Parkwa Quito 0 spot y

505958575 vacation 245 Toney Penna Dr. Babilonia 0 spot

ADD_SSN ADD_TYPE ADD_LINE1 ADD_LINE2 ADD_CITY ADD_Z ------454647484 vacation 333 Southern Boulevar Ibarra 0 spot d

932184567 vacation 12189 US Highway 1 San Jose 0 spot

47 rows selected.

Tuples in table DEPENDENT

DEP_EMP_SSN DEP_NAME DEP_BIRTH DEP_SEX DEP_RELATION ------123456789 Maria 28-JUN-90 F daughter 987654321 Sonia 27-FEB-91 F daughter 543219876 Pablo 26-MAR-92 M son 918273645 Eulogio 25-APR-93 M son 98765432 Francis 24-MAY-94 F daughter 123456789 Teo 23-JUN-95 M son 987654321 Virgil 22-JUL-96 M son 543219876 Demostenes 21-AUG-97 M son 182838485 Trisha 20-SEP-98 F daughter 273747576 Penny 19-OCT-99 F daughter 564636261 Tania 18-NOV-00 F daughter

DEP_EMP_SSN DEP_NAME DEP_BIRTH DEP_SEX DEP_RELATION ------908070605 Dora 17-DEC-01 F daughter 403020109 Paul 16-JUN-02 M son 101918171 Bob 15-FEB-03 M son 101918171 Sergio 14-MAR-04 M son 292827262 Tania 13-APR-03 F daughter 321098678 Tony 12-MAY-02 M son 110220330 Tony 11-JUN-01 M son 220330440 George 10-JUL-00 M son 400300200 Gina 09-AUG-99 F daughter 505958575 Prince 08-SEP-98 M son 220330440 Zhijian 07-OCT-97 F daughter

DEP_EMP_SSN DEP_NAME DEP_BIRTH DEP_SEX DEP_RELATION ------400300200 Tay 06-NOV-96 F daughter 505958575 Federico 05-DEC-95 M son 61928473 Charlie 04-JAN-94 M son 551552553 Hector 03-FEB-93 M son 440449448 Italo 02-MAR-92 M son 334335336 James 01-APR-91 M son DCIS850-doylet Page 44

334335336 Jessica 02-MAY-90 F daughter 123321123 Olivo 03-JUN-91 F daughter 987789987 Kevin 04-JUL-92 M son 768594032 Klever 05-AUG-93 M son 771772773 Laura 06-SEP-94 F daughter

DEP_EMP_SSN DEP_NAME DEP_BIRTH DEP_SEX DEP_RELATION ------717273747 Nancy 07-OCT-95 F daughter 717273747 Oscar 08-NOV-96 M son 656463626 Patrick 09-DEC-97 M son 656463626 Patricia 10-NOV-98 F daughter 932184567 Ronald 11-OCT-99 M son 932184567 Sara 12-SEP-00 F daughter

39 rows selected.

Tuples in table SUPPLIER

SUP_NUM SUP_NAME SUP_STATUS SUP_CITY ------1 FirstSupplier warning Lagos 12 AmeriSupplies good Boston 23 EuroSupplies good Paris 34 AfroSupplies warning Esmeraldas 45 AsianSupplies pending Tokio 56 PrimeSupplies good London

6 rows selected.

4. For each department, retrieve the department number and name, the number of employees, total and average salary of each department.

SQL> get fq4; 1 PROMPT; 2 PROMPT Department Employees and Salaries; 3 COLUMN department FORMAT A20; 4 COLUMN total_salary FORMAT 999,999,999.99; 5 COLUMN average_salary FORMAT 999,999.99; 6* SELECT d.dept_number || ' ' || d.dept_name AS department, count(emp_salary) AS employees, sum(emp_salary) AS total_salary, avg(emp_salary) as average_salary FROM DEPARTMENT d, EMPLOYEE e WHERE e.emp_dept_number = d.dept_number GROUP BY d.dept_number, d.dept_name;

SQL> str SP2-0042: unknown command "str" - rest of line ignored. SQL> start fq4;

Department Employees and Salaries

DEPARTMENT EMPLOYEES TOTAL_SALARY AVERAGE_SALARY ------1 Accounting 7 303,000.00 43,285.71 2 Management 7 277,678.00 39,668.29 3 Personnel 7 260,490.00 37,212.86 4 Marketing 7 286,680.00 40,954.29 5 Human Resources 7 349,110.00 49,872.86

DCIS850-doylet Page 45

5. For each employee, show how many projects the employee works on.

SQL> get fq5; 1 PROMPT; 2 PROMPT Employees and the number of Projects each works on; 3 COLUMN employee FORMAT A25; 4* SELECT e.emp_name_last || ', ' || e.emp_name_first || ' ' || e.emp_name_mi AS employee, COUNT(p.proj_name) AS projects FROM EMPLOYEE e, PROJECT p, WORKS_ON w WHERE e.emp_ssn = w.wo_ssn (+) AND w.wo_proj_num = p.proj_num GROUP BY e.emp_name_first, e.emp_name_last, e.emp_name_mi ORDER BY employee;

SQL> start fq5;

Employees and the number of Projects each works on

EMPLOYEE PROJECTS ------Aisner, Jim I 1 Carbo, Francis C 1 David, Ashley L 2 Davila, Gladys B 1 De La Torre, Ernest E 1 Denny, Jeffrey K 2 Duran, Eunice T 1 Gamboa, Joyce U 1 Green, Marie W 2 Hale, Dorothy S 2 Imparato, Frank R 1

EMPLOYEE PROJECTS ------Jasso, John I 2 Jones, Keith D 1 Jones, Kevin B 2 Kling, Edward F 1 Laux, Richard A 2 Lawler, Larry F 1 Lobos, Anna G 1 Mekala, Roger Z 2 Millan, Addiel O 1 Mueller, Robert Y 2 Ogus, Linda X 2

EMPLOYEE PROJECTS ------Okeefe, Monica V 2 Olive, Brenda N 2 Ramseyer, Sam M 2 Richardson, Mary C 1 Ruby, Lisa H 1 Sanchez, Estuardo Q 1 Sucre, Peter D 1 Sudan, Kenneth E 1 Terrell, Carol J 2 Thomas, Dana H 2 Torres, Irma A 1

EMPLOYEE PROJECTS ------Torrido, Ronald P 1 DCIS850-doylet Page 46

34 rows selected.

6. For each employee, show how many projects the employee manages.

SQL> get fq6; 1 PROMPT; 2 PROMPT Employees and the number of Projects each manage; 3 COLUMN employee FORMAT A25; 4* SELECT e.emp_name_last || ', ' || e.emp_name_first || ' ' || e.emp_name_mi AS employee, COUNT(p.proj_name) AS projects FROM EMPLOYEE e, PROJECT p WHERE e.emp_ssn = p.proj_mgr_ssn GROUP BY e.emp_name_last, e.emp_name_first, e.emp_name_mi; SQL> start fq6;

Employees and the number of Projects each manage

EMPLOYEE PROJECTS ------Jasso, John I 1 Lobos, Anna G 3 Ogus, Linda X 1 Sanchez, Estuardo Q 1 Sudan, Kenneth E 1

7. For each employee, show how many dependents the employee has.

SQL> get fq7; 1 PROMPT; 2 PROMPT Employees and the number of their Dependents; 3 COLUMN employee FORMAT A25; 4* SELECT e.emp_name_last || ', ' || e.emp_name_first || ' ' || e.emp_name_mi AS employee, COUNT(d.dep_relation) AS dependents FROM EMPLOYEE e, DEPENDENT d WHERE e.emp_ssn = d.dep_emp_ssn (+) GROUP BY e.emp_name_last, e.emp_name_first, e.emp_name_mi;

SQL> start fq7;

Employees and the number of their Dependents

EMPLOYEE DEPENDENTS ------Aisner, Jim I 2 Carbo, Francis C 1 David, Ashley L 1 Davila, Gladys B 1 De La Torre, Ernest E 2 Denny, Jeffrey K 1 Duran, Eunice T 0 Gamboa, Joyce U 0 Green, Marie W 1 Hale, Dorothy S 2 Imparato, Frank R 2

EMPLOYEE DEPENDENTS ------Jasso, John I 1 Jones, Keith D 2 Jones, Kevin B 1 Kling, Edward F 2 DCIS850-doylet Page 47

Laux, Richard A 1 Lawler, Larry F 0 Lobos, Anna G 0 Mekala, Roger Z 1 Millan, Addiel O 1 Mueller, Robert Y 2 Ogus, Linda X 1

EMPLOYEE DEPENDENTS ------Okeefe, Monica V 1 Olive, Brenda N 1 Ramseyer, Sam M 2 Richardson, Mary C 1 Ruby, Lisa H 0 Sanchez, Estuardo Q 2 Sucre, Peter D 2 Sudan, Kenneth E 2 Tedesco, Laura G 0 Terrell, Carol J 1 Thomas, Dana H 1

EMPLOYEE DEPENDENTS ------Torres, Irma A 0 Torrido, Ronald P 1

35 rows selected.

8. For each employee, as a supervisor, how many supervisees the employee supervises.

SQL> get fq8; 1 PROMPT; 2 PROMPT Employees as Supervisors and their count of Supervisees; 3 COLUMN supervisor FORMAT A25; 4 COLUMN supervisees FORMAT A25; 5* SELECT e.emp_name_last || ', ' || e.emp_name_first || ' ' || e.emp_name_mi AS supervisor, COUNT(s.emp_ssn) AS suprevisees FROM EMPLOYEE e, EMPLOYEE s WHERE e.emp_ssn = s.emp_supervisor_ssn GROUP BY e.emp_name_last, e.emp_name_first, e.emp_name_mi; SQL> start fq8;

Employees as Supervisors and their count of Supervisees

SUPERVISOR SUPREVISEES ------De La Torre, Ernest E 1 Denny, Jeffrey K 2 Green, Marie W 2 Jones, Keith D 5 Kling, Edward F 3 Millan, Addiel O 2 Ogus, Linda X 2 Okeefe, Monica V 2 Richardson, Mary C 1 Sanchez, Estuardo Q 1 Sucre, Peter D 2

SUPERVISOR SUPREVISEES ------DCIS850-doylet Page 48

Terrell, Carol J 2 Thomas, Dana H 2 Torrido, Ronald P 3

14 rows selected.

9. List the suplier names of suppliers who supply all parts.

SQL> get fq9; 1 PROMPT; 2 PROMPT Supplier(s) who supply all parts; 3 COLUMN supplier FORMAT A20; 4 SELECT DISTINCT s.sup_name AS supplier FROM SUPPLIED_BY b, SUPPLIER s, PART p WHERE b.sb_supplier = s.sup_num AND b.sb_part = p.part_num AND 0 = 5 (SELECT COUNT(q.part_num) FROM PART q WHERE q.part_num NOT IN 6* (SELECT c.sb_part FROM SUPPLIED_BY c WHERE c.sb_supplier = s.sup_num)); SQL> start fq9;

Supplier(s) who supply all parts

SUPPLIER ------EuroSupplies

10. Get part numbers for parts supplied by a supplier in London.

SQL> get fq10; 1 PROMPT; 2 COLUMN part FORMAT 99999; 3 PROMPT Parts supplied by Supplier in London; 4* SELECT b.sb_part AS part FROM SUPPLIER s, SUPPLIED_BY b WHERE b.sb_supplier = s.sup_num AND s.sup_city = 'London';

SQL> start fq10;

Parts supplied by Supplier in London

PART ------2 6

11. Get project names for projects supplied by Supplier 1.

SQL> get fq11; 1 PROMPT; 2 PROMPT Projects supplied by Supplier 1 3 COLUMN project FORMAT A20; 4* SELECT DISTINCT p.proj_name AS project FROM PROJECT p, USES u, SUPPLIED_BY s WHERE p.proj_num = u.use_project AND u.use_part = s.sb_part AND s.sb_supplier = 1 ORDER BY p.proj_name; SQL> start fq11;

Projects supplied by Supplier 1

PROJECT ------DCIS850-doylet Page 49

Project Five Project Four Project One Project Seven Project Six Project Three Project Two

7 rows selected.

12. Get the list of subparts used by each part.

SQL> get fq12; 1 PROMPT; 2 PROMPT Subparts used by each Part; 3 COLUMN part FORMAT A15; 4 COLUMN subpart FORMAT A15; 5 BREAK ON part; 6* SELECT p.part_name AS part, s.part_name AS subpart FROM PART p, PART s, SUBPART_OF o WHERE o.so_part = p.part_num AND o.so_subpart = s.part_num;

SQL> start fq12;

Subparts used by each Part

PART SUBPART ------Reading Tool Magnifier Handle Tool Chest Reading Tool Writing Tool Writing Tool Eraser

13. Get the part numbers for parts supplied to all projects in London.

SQL> get fq13; 1 PROMPT; 2 PROMPT Parts supplied to Projects in London 3* SELECT DISTINCT u.use_part AS part_number FROM USES u, PROJECT p, LOCATION l WHERE u.use_project = p.proj_num AND p.proj_dept_num = l.loc_dept_num AND l.loc_city = 'London';

SQL> start fq13;

Parts supplied to Projects in London

PART_NUMBER ------2 3

14. Get supplier numbers for suppliers supplying some project with part Part 1 in a quantity greater than the average shipment quantity of part Part 1 for that project.

SQL> get fq14; 1 PROMPT; 2 PROMPT Suppliers supplying more than the average of Part 1 per Project. DCIS850-doylet Page 50

3* SELECT s.sb_supplier AS suppliers, u.use_project AS projects FROM USES u, SUPPLIED_BY s WHERE u.use_part = s.sb_part AND s.sb_part = 1 AND s.quantity > (SELECT AVG(t.quantity) FROM USES v, SUPPLIED_BY t WHERE v.use_part = t.sb_part AND v.use_project = u.use_project AND v.use_part = 1); SQL> start fq14;

Suppliers supplying more than the average of Part 1 per Project.

SUPPLIERS PROJECTS ------12 1 34 1

15. Get supplier numbers for suppliers who supply the same part to all projects.

SQL> get fq15; 1 PROMPT; 2 PROMPT Suppliers of Parts sent to all Projects; 3 SELECT s.sb_supplier AS supplier_, s.sb_part AS part_ FROM SUPPLIED_BY s WHERE s.sb_part IN ( 4 SELECT u.use_part FROM USES u WHERE 0 = ( 5 SELECT COUNT(p.proj_num) FROM PROJECT p WHERE p.proj_num NOT IN 6 (SELECT v.use_project FROM USES v WHERE v.use_part = u.use_part) 7 GROUP BY p.proj_num 8* ) );

SQL> start fq15;

Suppliers of Parts sent to all Projects

SUPPLIER_ PART_ ------1 2 23 2 34 2 45 2 56 2

16. For each part, list all its direct and indirect subparts that belong to the part.

SQL> get fq16; 1 SELECT LPAD(' ',(level-1)*5) || t.so_part || ' -> ' || t.so_subpart AS part_to_subpart_levels 2 FROM SUBPART_OF t 3 CONNECT BY PRIOR t.so_subpart = t.so_part 4* START WITH t.so_part IN ( SELECT s.so_part FROM SUBPART_OF s); SQL> start fq16;

PART_TO_SUBPART_LEVELS ------1 -> 2 1 -> 3 4 -> 1 1 -> 2 1 -> 3 4 -> 5 5 -> 6 5 -> 6 DCIS850-doylet Page 51

8 rows selected.

17. For each employee, list all his/her direct or indirect supervisees the employee supervises.

SQL> get fq17; 1 PROMPT; 2 PROMPT List of Employees and their direct and indirect Supervisees; 3 COLUMN supervisees FORMAT A60; 4 BREAK ON supervisor; 5 SELECT emp_supervisor_ssn AS supervisors, LPAD(' ', 10*(Level -1)) || emp_ssn AS supervisees 6 FROM EMPLOYEE 7 START WITH emp_ssn IN (SELECT e.emp_ssn FROM EMPLOYEE e ) 8* CONNECT BY emp_supervisor_ssn = PRIOR emp_ssn;

SQL> start fq17;

List of Employees and their direct and indirect Supervisees

SUPERVISORS SUPERVISEES ------61928473 551552553 551552553 334335336 551552553 123321123 61928473 440449448 440449448 987789987 440449448 768594032 110220330 220330440 220330440 505958575 110220330 400300200 110220330 483920756 123456789 543219876

SUPERVISORS SUPERVISEES ------543219876 987654321 987654321 918273645 543219876 10203040 123456789 98765432 123456789 919293949 182838485 564636261 564636261 273747576 564636261 292827262 182838485 908070605 908070605 403020109 908070605 101918171

SUPERVISORS SUPERVISEES ------220330440 505958575 321098678 110220330 110220330 220330440 220330440 505958575 110220330 400300200 110220330 483920756 321098678 928372891 440449448 987789987 440449448 768594032 543219876 987654321 DCIS850-doylet Page 52

987654321 918273645

SUPERVISORS SUPERVISEES ------543219876 10203040 551552553 334335336 551552553 123321123 564636261 273747576 564636261 292827262 717273747 656463626 717273747 565758595 717273747 505958577 717273747 454647484 717273747 932184567 771772773 717273747

SUPERVISORS SUPERVISEES ------717273747 656463626 717273747 565758595 717273747 505958577 717273747 454647484 717273747 932184567 908070605 403020109 908070605 101918171 987654321 918273645 123456789 123456789 543219876 543219876 987654321

SUPERVISORS SUPERVISEES ------987654321 918273645 543219876 10203040 123456789 98765432 123456789 919293949 182838485 182838485 564636261 564636261 273747576 564636261 292827262 182838485 908070605 908070605 403020109 908070605 101918171

SUPERVISORS SUPERVISEES ------321098678 321098678 110220330 110220330 220330440 220330440 505958575 110220330 400300200 110220330 483920756 321098678 928372891 61928473 61928473 551552553 551552553 334335336 551552553 123321123

SUPERVISORS SUPERVISEES ------61928473 440449448 440449448 987789987 440449448 768594032 DCIS850-doylet Page 53

771772773 771772773 717273747 717273747 656463626 717273747 565758595 717273747 505958577 717273747 454647484 717273747 932184567

87 rows selected.

18. List the employees who work on all the projects except the project control by Department 4.

SQL> get fq18; 1 PROMPT; 2 PROMPT Employees working on all Projects not controlled by Department 4; 3 SELECT emp_ssn FROM EMPLOYEE WHERE NOT EXISTS ( 4 (SELECT proj_num FROM PROJECT WHERE proj_dept_num <> 4) 5 MINUS 6 (SELECT wo_proj_num FROM WORKS_ON WHERE wo_ssn = emp_ssn) 7* );

SQL> start fq18;

Employees working on all Projects not controlled by Department 4

no rows selected

19. List the projects worked by every employee.

SQL> get fq19; 1 PROMPT; 2 PROMPT Projects worked by every employee; 3 COLUMN employee FORMAT A30; 4 COLUMN project FORMAT A15; 5 BREAK ON employee; 6* SELECT e.emp_name_last || ', ' || e.emp_name_first || ' ' || e.emp_name_mi AS employee, p.proj_name AS project FROM EMPLOYEE e, PROJECT p, WORKS_ON w WHERE e.emp_ssn = w.wo_ssn AND w.wo_proj_num = p.proj_num ORDER BY employee;

SQL> start fq19;

Projects worked by every employee

EMPLOYEE PROJECT ------Aisner, Jim I Project Five Carbo, Francis C Project Four David, Ashley L Project Two Project Seven Davila, Gladys B Project Five De La Torre, Ernest E Project Two Denny, Jeffrey K Project One Project Seven Duran, Eunice T Project Five Gamboa, Joyce U Project One Green, Marie W Project Three DCIS850-doylet Page 54

EMPLOYEE PROJECT ------Green, Marie W Project Six Hale, Dorothy S Project Four Project Three Imparato, Frank R Project Three Jasso, John I Project Four Project Seven Jones, Keith D Project Five Jones, Kevin B Project Three Project Six Kling, Edward F Project One Laux, Richard A Project Two

EMPLOYEE PROJECT ------Laux, Richard A Project Six Lawler, Larry F Project Two Lobos, Anna G Project Two Mekala, Roger Z Project One Project Six Millan, Addiel O Project Five Mueller, Robert Y Project Five Project Six Ogus, Linda X Project Four Project Six Okeefe, Monica V Project Two

EMPLOYEE PROJECT ------Okeefe, Monica V Project Six Olive, Brenda N Project Four Project Seven Ramseyer, Sam M Project Three Project Seven Richardson, Mary C Project Four Ruby, Lisa H Project Four Sanchez, Estuardo Q Project Two Sucre, Peter D Project Three Sudan, Kenneth E Project One Terrell, Carol J Project Five

EMPLOYEE PROJECT ------Terrell, Carol J Project Seven Thomas, Dana H Project Three Project Seven Torres, Irma A Project One Torrido, Ronald P Project One

49 rows selected.

20. List the departments that controls all the projects that Joyce English works on.

SQL> get fq20; 1 PROMPT; 2 PROMPT Department that controls all Projects where Joyce English works; 3 SELECT d.dept_name AS department FROM DEPARTMENT d WHERE NOT EXISTS 4 ( 5 (SELECT w.wo_proj_num FROM WORKS_ON w, EMPLOYEE e WHERE w.wo_ssn = DCIS850-doylet Page 55 e.emp_ssn AND e.emp_name_first = 'Joyce' AND (e.emp_name_last = 'English' OR e.emp_name_maiden = 'English')) 6 MINUS 7 (SELECT proj_num FROM PROJECT WHERE proj_dept_num = d.dept_number) 8* );

SQL> start fq20;

Department that controls all Projects where Joyce English works

DEPARTMENT ------Human Resources DCIS850-doylet Page 56

8. Write a detailed report Write a detailed report of the database design and implementation.

Translating the requirements from free-flow text into possible relations was

helpful to define the fields or attributes needed by the database, in an universal

relation. Mapping the fields and their relationships on the universal relation, provides

a better understanding of the big picture, to extract its graphical representation or

Entity Relationship (ER) Diagram with attributes forming relations and their

relationships.

Once the ER Diagram was in place and compared with the original

requirements, many more details could be graphically included, like levels of

participation, subclasses, the degree of each relationship, cardinality ratios,

multivalue attributes, key attributes, and weak entities. After the ER Diagram was

considered complete, its plain-text conceptual schema was conceived, including the

data type and reasonable size of each attribute.

Continuously comparing with the original requirements, for consistency, the

conceptual schema was decomposed into the relational database schema, and the list

of all the join paths. Each join path defines the relationship between a foreign key and

a primary key, as shown on the relational database schema.

Normalization was reasoned from the universal relation, to make sure the

relationships on the extracted tables where at least in 3NF. It was during this process

that most unspecified requirements and their appropriate assumptions were included

for completeness, producing changes to the ER Diagram and its derivatives. It was

during normalization that I realized the need to have a separate Address table, and

that the Employee's name components did not need to be in a separate table. DCIS850-doylet Page 57

Implementing the database became a challenge, because the creation of tables had to follow a specific sequence to guarantee the availability of their pre- requirements. In the case of the recursively related tables like Department and

Employee, the first table was created without the foreign key pointing to the inexistent table, and that key added after that second table was created. A similar challenge was to sequence the dropping of the tables, and breaking the recursive relationship, to automate the deletion of the whole database and try the implementation again.

A spreadsheet and a formula for each table was required to automate the loading of all the tables, with enough details to run the final test queries. As each test query was built, new tuples were added to obtain satisfactory results. The final implementation of practice queries was also helpful to define additional assumptions, and to show the possibility of improving the database, with new concerns like the suppressing of leading zeroes on social security numbers.

Recommended publications