Академический Документы
Профессиональный Документы
Культура Документы
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
EG
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
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.
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.
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
;
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.