Вы находитесь на странице: 1из 6

University Of Wollongong, Dubai Campus

CSCI235 – Databases
Assignment 2
Date of submission: Thursday 5 pm-Week 13.
Note:
1) This assignment is a group work of no more than two students.
2) 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.
[2.5 marks]
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. state the strongest normal form that the relation is in (1NF, 2NF, 3NF and
BCNF)
b. If it is not in BCNF, decompose it into a collection of BCNF relations.

R1(A,C,B,D,E), A B, C  D

Answer:
It is 1NF
The BCNF decomposition is: (A,B) (C,D) and (A,C,E)

2- Suppose you are given a relation R with four attributes ABCD. For each of the
following sets of FDs, assuming those are the only dependencies that hold for R. Do
the following: [7.5 marks 2.5 marks each]
a. Identify the candidate key(s) for R
b. Identify the best normal form that R satisfies (1NF, 2NF, 3NF, BCNF)
c. If R is not in BCNF, decompose it into a set of BCNF relations that preserves
the dependencies.

I. C  D, C  A, B  C
Candidate key(B)
2NF
(A,C,D) and C  D, C  A BCNF
(B,C) and B  C BCNF
II. ABC  D, D  A
Key(ABC), 3NF and it is not possible to make it BCNF

III. AB  C, AB  D, C  A, D  B
Candidate Key(AB, BC, AD, CD) 3NF but can not be BCNF

3- Consider the attribute set R= ABCDEGH and the following FD set: [10 marks, 2.5
each]
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.

I. ABCD
AB  C, AC  B, B  D, BC  A
1NF
(A,B,C) and AB  C, AC  B, BC  A (candidate keys(AB, AC, BC) BCNF
(B,D) and B  D, (candidate keys(B)) BCNF

II. DCEGH
EG
1NF
(D,C,H,E) BCNF key(D,C,H,E)
(E,G) E  G, key(E) BCNF

III. ACEH
No dependency so, key(A,C,E,H)
BCNF

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}

{AB , BC, ABDE (AD  E, B  D), , EG (E  G )}

This decomposition is not lossless because


This dependency AB  C tells us that value of C depends ob both A and B but in table BC
we only have B, so we do not have a complete foreign key to BC from AB or ABDE

or dependency preserving because:


the dependencies AB  C, AC  B, BC  A, are not part of any tables.
Transaction Management:
Objectives:
The objective of this assignment is to practice assigning isolation levels to control
concurrency in database transactions. [10 marks, 2.5 each]

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, state the SQL isolation level you would use and
explain why you chose it.

1. Enroll a student identified by her snum into the class named ’Introduction to
Database Systems’.

Read committed (because it is lowest isolation level which is not read only)

2. Change enrollment for a student identified by her snum from one class to another
class.

Read committed if no other insert into enrollment is happening or


SERIALIZABLE. To prevent inserting the same snum and the same course into the table.

3. Assign a new faculty member identified by his fid to the class with the least number
of students.

SERIALIZABLE

4. For each class, show the number of students enrolled in the class.

Read uncommitted because we are just looking for a sum in all classes.
But in order to make the sums accurate, it has to be SERIALIZABLE
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. (4 marks)


A.2. Run the program (on the next page) and show the resulting table. (6 marks)

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 Table
Employee Year_Experience Salary
10001 5 5000
10002 10 10000
10003 2 5000
10004 4 5000
10005 3 3000
10006 8 10000
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;

Employee Table
Employee Year_Experience Salary
10001 5 5000
10002 10 10500

10004 4 5000
10005 3 3000
10006 8 10500

Deleted 2 5000
10003
Exercise 19.7 Suppose you are given a relation R with four attributes ABCD. For
each of the following sets of FDs, assuming those are the only dependencies that hold
for R, do the following: (a) Identify the candidate key(s) for R. (b) Identify the best
normal form that R satisfies (1NF, 2NF, 3NF, or BCNF). (c) If R is not in BCNF,
decompose it into a set of BCNF relations that preserve the dependencies.
1. C → D, C → A, B → C
2. B → C, D → A
3. ABC → D, D → A
4. A → B, BC → D, A → C
5. AB → C, AB → D, C → A, D → B
Answer 19.7
1. (a) Candidate keys: B
(b) R is in 2NF but not 3NF.
Schema Refinement and Normal Forms 193
(c) C → D and C → A both cause violations of BCNF. One way to obtain a
(lossless) join preserving decomposition is to decompose R into AC, BC, and
CD.
2. (a) Candidate keys: BD
(b) R is in 1NF but not 2NF.
(c) Both B → C and D → A cause BCNF violations. The decomposition: AD,
BC, BD (obtained by first decomposing to AD, BCD) is BCNF and lossless
and join-preserving.
3. (a) Candidate keys: ABC, BCD
(b) R is in 3NF but not BCNF.
(c) ABCD is not in BCNF since D → A and D is not a key. However if we split
up R as AD, BCD we cannot preserve the dependency ABC → D. So there
is no BCNF decomposition.
4. (a) Candidate keys: A
(b) R is in 2NF but not 3NF (because of the FD: BC → D).
(c) BC → D violates BCNF since BC does not contain a key. So we split up R
as in: BCD, ABC.
5. (a) Candidate keys: AB, BC, CD, AD
(b) R is in 3NF but not BCNF (because of the FD: C → A).
(c) C → A and D → B both cause violations. So decompose into: AC, BCD
but this does not preserve AB → C and AB → D, and BCD is still not
BCNF because D → B. So we need to decompose further into: AC, BD,
CD. However, when we attempt to revive the lost functioanl dependencies
by adding ABC and ABD, we that these relations are not in BCNF form.
Therefore, there is no BCNF decomposition.

Вам также может понравиться