You are on page 1of 4

University Of Wollongong in Dubai

CSCI235 Databases

Assignment 2
SET 4
Date of submission: Thursday 5 pm-Week 13.
Note:
This assignment is a group work of no more than two students. Detection of plagiarism or
copying of work will lead to severe penalty.

Normalization
Objectives:
The objective of this assignment is to normalize the given conceptual database schema.
1. Consider the following collection of relations and dependencies. Assume that each
relation is obtained through decomposition from a relation with attributes ABCDEFGHI
and that all the known dependencies over relation ABCDEFGHI are listed for each
question.
a. Identify the candidate key(s) for R
b. state the strongest normal form that the relation is in (1NF, 2NF, 3NF and BCNF)
c. If it is not in BCNF, decompose it into a collection of BCNF relations that
preserves the dependencies.
d. If it is not possible to decompose it to BCNF, then decompose it to highest normal
form possible.
I.
II.
III.
IV.

R1(A,C,B,D,E),
A BC, E D == A->B,A->C , E-> D (3NF) keys A, E
A D, D B, D C, D E == A->B, D->C,D->E (3NF) keys A, D
DE C, CB A == D->C,E->C,C->A,B->A (3NF) keys d,e,c,b
AB C, AB D, A C, B D== A->C ,B->C,A->D,B->D(3NF) keys a, b

2. Consider the attribute set R= ABCDEGH and the following FD set:


F= { AB C, AC B, AD E, B D, BC A, E G}
a. Name the strongest normal form that each relation satisfies. Decompose it into a
collection of BCNF relations if it is not in BCNF.
V.
VI.
VII.

ABCD == A->B,A->C.
DCEGH==E->G,D->E.
ACEH== A->C.

b. which of the following decompositions of R=ABCDEG with the same set of


dependencies F, is a) dependency preserving b) lossless-join?
{AB, BC, ABDE, EG}

Transaction Management:
Objectives:
The objective of this assignment is to practice assigning isolation levels to control
concurrency in database transactions.

Consider the university enrollment database schema:


Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(name: string, meets at: time, room: string, fid: integer)
Enrolled(snum: integer, cname: string)
Faculty(fid: integer, fname: string, deptid: integer)
The meaning of these relations is straightforward; for example, Enrolled has one record
per student-class pair such that the student is enrolled in the class.
For each of the following transactions,
a. Write the SQL command that implements them
b. Write SQL SET ISOLATION LEVEL and explain why you chose it.
T1.
Create a class name: Introduction to Database Systems
Move all students from class Interactive Systems to Introduction to Database Systems

T2.
Enroll all MIS major students in the class Database I that meets at KV-312
T3.
Change the faculty id of all classes that their name has Database to fid of 110
T4.
For each class, show the number of students enrolled in the class.
T5.
For all classes with maximum students enrolled in them return the class name and number of
students

PL/SQL
Objectives:
The objective of this assignment is to practice with PL/SQL.
A. Answer the following questions based on the PL/SQL program below
You are working for a company and your boss gives you the following table Employee
and a stored procedure below and a program (on next page).
A.1. Describe what the program does.
The procedure takes in a the employee id and new salary
If the id is in database and salary is not null then it updates it to new salary provided
According to number of years of experience
Otherwise it gives an error message
A.2. Run the program (on the next page) and show the resulting table. (if you find a bug in the
program, you need to fix them first)

PROCEDURE update_ES (iSSN INTEGER, fNewSalary NUMBER) IS


fCurSalary NUMBER(10, 2);
missing_salary EXCEPTION
BEGIN
SELECT Salary INTO fCurSalary FROM Employee WHERE SSN = iSSN;
IF fCurSalary IS null THEN RAISE missing_salary;
ELSE
UPDATE Employee SET Salary = fNewSalary WHERE SSN = iSSN;
END IF;
COMMIT;
EXCEPTION
WHEN NO_ DATA_ FOUND THEN INSERT INTO item_audit
VALUES (iSSN, 'Invalid Employee identifier.'); COMMIT;
WHEN missing_salary THEN INSERT INTO item_audit
VALUES (iSSN, 'Salary is null.'); COMMIT;
WHEN OTHERS THEN
ROLLBACK;
INSERT INTO item_audit VALUES (iSSN, 'Miscellaneous error.');
COMMIT;
END update_ES;

Employee
10001
10002
10003
10004
10005
10006

Employee Table
Year_Experience
5
10
2
4
3
8

Salary
5000
10000
5000
5000
3000
10000

10001
10002
10003
10004
10005
10006

0.05
0.1
0.02
0.04
0.03
0.08

5000
10000
5000
5000
3000
10000

5250
11000
5100
5200
3090
10800

DECLARE
CURSOR emp_cursor IS
SELECT emp_year_exp, emp_salary, emp_SSN FROM Employee;
emp_rec item%ROWTYPE;
BEGIN
FOR emp_rec IN emp_cursor LOOP
IF (emp_rec.emp_year_exp > 10)
THEN
update_ES(emp_rec.emp_SSN, emp_rec.salary +
emp_rec.salary * 0.10)
ELSIF ((emp_rec.emp_year_exp <= 10) AND
(emp_rec.emp_year_exp > 5))
THEN
update_ES(emp_rec.emp_SSN, item emp_rec.salary +
emp_rec.salary * 0.05);
ELSIF ((emp_rec.emp_year_exp < 5) AND
(emp_rec.emp_year_exp >= 3))
THEN
;
ELSIF ((emp_rec.emp_year_exp < 3)
DELETE Employee WHERE CURRENT OF emp_cursor;
END IF;
END LOOP;
COMMIT;
-- Commit the transaction
WHEN OTHERS THEN
ROLLBACK;
END;

You might also like