csci235 autumn2014 assignments assignment 2
TRANSCRIPT
-
8/10/2019 CSCI235 Autumn2014 Assignments Assignment 2
1/4
University Of Wollongong in DubaiCSCI235Databases
Assignment 2S E T 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 eachrelation 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 normalform possible.
R1(A,C,B,D,E),I. ABC, E D == A->B,A->C , E-> D (3NF) keys A, E
II. A
D, D
B, D
C, D
E == A->B, D->C,D->E (3NF) keys A, DIII. DE C, CB A == D->C,E->C,C->A,B->A (3NF) keys d,e,c,bIV. 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. ABCD == A->B,A->C.VI. DCEGH==E->G,D->E.
VII. 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}
-
8/10/2019 CSCI235 Autumn2014 Assignments Assignment 2
2/4
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 themb. Write SQL SET ISOLATION LEVEL and explain why you chose it.
T1.
Create a class name: Introduction toDatabase SystemsMove all students from class Interactive Systems to Introduction toDatabase Systems
T2.
Enroll all MIS major students in the class Database Ithat meets at KV-312
T3.
Change the faculty id of all classes that their name has Databaseto 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
-
8/10/2019 CSCI235 Autumn2014 Assignments Assignment 2
3/4
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 Employeeand 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 salaryIf the id is in database and salary is not null then it updates it to new salary providedAccording to number of years of experienceOtherwise 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 theprogram, you need to fix them first)
Employee Table
Employee Year_Experience Salary10001 5 5000
10002 10 10000
10003 2 5000
10004 4 5000
10005 3 3000
10006 8 10000
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;
-
8/10/2019 CSCI235 Autumn2014 Assignments Assignment 2
4/4
10001 0.05 5000 5250
10002 0.1 10000 11000
10003 0.02 5000 5100
10004 0.04 5000 5200
10005 0.03 30003090
10006 0.08 10000 10800
DECLARECURSOR emp_cursor ISSELECT emp_year_exp, emp_salary, emp_SSN FROM Employee;
emp_rec item%ROWTYPE;
BEGINFOR 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 5))
THENupdate_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 THENROLLBACK;
END;