CS 631 Review Project Given The Following Database
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;
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
FNAME LNAME
---------------------------------------------
Franklin Wong
Ramesh Narayan
Joyce English
John Smith
no rows selected
FNAME LNAME
---------------------------------------------
John Smith
Ramesh Narayan
Joyce English