0% found this document useful (0 votes)
78 views

CS 631 Review Project Given The Following Database

This document provides details for a review project on a COMPANY relational database including an ER diagram, relationship diagram, and a series of SQL queries to perform on the database. The queries retrieve information on employees, projects, departments and their relationships and properties.

Uploaded by

Mehsara Irfan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

CS 631 Review Project Given The Following Database

This document provides details for a review project on a COMPANY relational database including an ER diagram, relationship diagram, and a series of SQL queries to perform on the database. The queries retrieve information on employees, projects, departments and their relationships and properties.

Uploaded by

Mehsara Irfan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CS 631 Review Project

Given the following database:

Questions:

1. ER diagram
2. Relationship diagram for the database.
3. Perform queries.

1
1. ER diagram

2. Relationship diagram:

2
3. Queries:

Specify the following queries in SQL on the COMPANY relational database and show the result
of each query.

a. Retrieve the name and address of all employees who work for the ‘Research’ department.

b. For every project located in ‘Stafford’, list the project number, the controlling department
number, and the department manager’s last name, address, and birth date.

c. Retrieve the salary of every employee and all distinct salary values.

d. Make a list of all project numbers for projects that involve an employee whose last name is
‘Smith’, either as a worker or as a manager of the department that controls the project.

e. Retrieve the names of all employees in department 5 who work more than 10 hours per
week on the ProductX project.

f. List the names of all employees who have a dependent with the same first name as
themselves.

g. Find the names of all employees who are directly supervised by ‘Franklin Wong’.

h. Retrieve a list of employees and the projects they are working on, ordered by department and, within
each department, ordered alphabetically by last name, then first name.

i. Show the resulting salaries if every employee working on the ‘ProductX’ project is given a 15 percent
raise.

3
Perform Queries
a. SELECT fname, lname, address
FROM employee, department
WHERE dname='Research' AND dnumber=dno;

FNAME LNAME ADDRESS

Franklin Wong 638 Voss, Houston, TX


John Smith 731 Fondren,Houston, TX
Ramesh Narayan 975 Fire Oak,Humble, TX
Joyce English 5631 Rice,Houston, TX

b. SELECT pnumber, dnum, lname, address, bdate


FROM project, department, employee
WHERE dnum=dnumber AND mgr_ssn=ssn AND plocation='Stafford';

PNUMBER DNUM LNAME ADDRESS BDATE

30 4 Wallace 291 Berry,Bellaire, TX 20-JUN-41


10 4 Wallace 291 Berry,Bellaire, TX 20-JUN-41

c. SELECT ALL salary


FROM employee;

SALARY
----------
55000
40000
43000
30000
38000
25000
25000
25000

SELECT DISTINCT(salary)
FROM employee;

SALARY
----------
38000
55000
43000
30000
40000
25000

4
d. (SELECT DISTINCT(pnumber)
FROM project, department, employee
WHERE dnum=dnumber AND mgr_ssn=ssn AND lname='Smith')
UNION
(SELECT DISTINCT(pnumber)
FROM project, works_on, employee
WHERE pnumber=pno AND essn=ssn AND lname= 'Smith');

PNUMBER
1
2

e. SELECT distinct fname, lname


FROM employee e, works_on w
WHERE e.dno = 5 AND w.pno =1 AND w.hours > 10.0;

FNAME LNAME
---------------------------------------------
Franklin Wong
Ramesh Narayan
Joyce English
John Smith

f. SELECT fname, lname


FROM employee e, dependent d
WHERE e.fname = d.dependent_name;

no rows selected

SQL> SELECT fname from employee;


FNAME
------------
James
Franklin
Jennifer
John
Ramesh
Joyce
Alicia
Ahmad

SQL> SELECT dependent_name from dependent;


DEPENDENT_NAME
Alice
Theodore
Joy
Abner
Michael
Alice
Elizabeth
5
g. SELECT fname, lname
FROM employee
WHERE super_ssn = 333445555;

[As supervisor ‘Franklin Wong’ has ssn = 333445555]

FNAME LNAME
---------------------------------------------
John Smith
Ramesh Narayan
Joyce English

h. SELECT d.dname, e.lname, e.fname, p.pname


FROM department d, employee e, works_on w, project p
WHERE d.dnumber=e.dno AND e.ssn=w.essn AND w.pno=p.pnumber
ORDER BY d.dname, e.lname, e.fname;

DNAME LNAME FNAME PNAME


---------------------------------------------------------------------------------------------------
Administration Jabbar Ahmad Computerization
Administration Jabbar Ahmad Newbanefits
Administration Wallace Jennifer Newbanefits
Administration Wallace Jennifer Reorganization
Administration Zelaya Alicia Computerization
Administration Zelaya Alicia Newbanefits
Headquarters Borg James Reorganization
Research English Joyce ProductY
Research English Joyce ProductX
Research Narayan Ramesh ProductZ
Research Smith John ProductX
Research Smith John ProductY
Research Wong Franklin ProductZ
Research Wong Franklin Computerization
Research Wong Franklin Reorganization
Research Wong FranklinProductY

i. SELECT e.fname, e.lname, 1.15*e.salary AS increased_sal


FROM employee e, project p
WHERE p.pnumber = 1 AND e.dno = p.dnum;

FNAME LNAME INCREASED_SAL

Franklin Wong 46000


John Smith 34500
Ramesh Narayan 43700
Joyce English 28750

You might also like