You are on page 1of 29

3NF AND BCNF LOSSLESS

DECOMPOSITIONS
WHY LOSSLESS DECOMPOSITION?
 Decompositions should always be lossless
 Lossless decomposition ensure that the information in
the original relation can be accurately reconstructed
based on the information represented in the decomposed
relations.
 It is important to check that decomposition does not lead
to bad design
 A good decomposition must not lead to loss of
information (lossy decomposition)
 Given instances of the decomposed relations, we may not be
able to reconstruct the corresponding instance of the original
relation – information loss
LOSSLESS DECOMPOSITION DEFINITION

 A set
of relation schemas { R1, R2,…,
Rn } is a lossless decomposition of R if

R = R1 U R2 U …..U Rn each Ri is a subset of


R ( for i = 1,2…,n)
 A decomposition {R1, R2,…, Rn} of a
relation R is called a lossless
decomposition for R if the natural join of
R1, R2,…, Rn produces exactly the
relation R.
EXAMPLE
LOSSY DECOMPOSITION
 In the previous example, additional tuples
are obtained along with original tuples
 Additional tuples leads to loss of
information
Lossy join decomposition
 The lossy decomposition violates entity
integrity restriction.
3NF LOSSLESS JOIN
DECOMPOSITION
THIRD NORMAL FORM
 For a relation to be in Third Normal Form, it must be in
Second Normal form and the following must satisfy −
 No non-key attribute is transitively dependent on prime key
attribute.
 Non key attributes are dependent on nonkey attributes
OR
 For any non-trivial functional dependency, X → A, then
either −
 X is a superkey or,
 A is prime attribute.
EXAMPLE

Consider the relation R(A,B,C,D,E) with FD’s


F = {AB  C, CB, A  D}. Is R in 3NF?
 R has two Keys ABE or ACE

 AB+ ={ABCD} ; AB is not a SK


 C+ = {CB} ;C is no a SK
 A+ = {AD} ; A is not a SK

 A  D: A is not super key and D is not a key attribute


EXAMPLE

1. Determine if the determinants are SKs


 AB+ ={ABCD} ; AB is not a SK
 C+ = {CB} ;C is no a SK
 A+ = {AD} ; A is not a SK

2. Determine the CKs for R


R has two CKs ABE or ACE
3. Determine if C, B, D are prime attributes
AB  C : C ⊆ ACE
CB : B ⊆ ABE
A  D : D ABE, ACE
 A  D: A is not super key and D is not a key attribute,
therefore R is not in 3NF
3NF LOSSLESS JOIN DECOMPOSITION
ALGORITHM
 We can always find a third normal form decomposition of a relation that
is lossless and that preserves dependencies.
 Given a universal relation R and a set of functional dependencies, G, on
R,
 INPUT: A relation R and a set F of functional dependencies that hold
for R.
 OUTPUT: A decomposition of R into a collection of relations, each of
which is in 3NF. The decomposition has the lossless-join and
dependency-preservation properties.
 METHOD: Perform the following steps:

 Find a minimal cover F for G,

 For each functional dependency X  A in G, use XA as the schema of


one of the relations in the decomposition.
 If none of the relation schemas from Step 2 is a superkey for R, add
another relation whose schema is a key for R.
EXAMPLE

 Consider the relation R(A,B,C,D,E) with FD’s F = {AB


 C, CB, A  D}
 F is minimal

 Take the attributes of each FD as a relation schema.


That is, we get relations R1(A,B,C), R2(B, C). and
R3(A,D).
 R has two Keys is ABE or ACE not contained R1, R2 or
R3. Thus, we must add one of them, say R4(A,B,E).
 R2 is contained in R1
 The final decomposition of R is thus R1(A,B,C), R3(A,D), and
R4 (A,B,E).
Consider relation R(ABCDE) with the following functional
dependencies F = {ABE; BC; CD; BDA; DE}
 Determine SK of R

Super keys ={AB, B, BD, BC, BE …}


 Find the minimal set of F

minimal set = {BC; CD; BA; DE}


 Normalize R to loss less 3NF decompositions.
 R1(B,C);
 R2(C,D);
 R3(B,A);
 R4(D,E)

Merge R1 and R3
 R1(B,A,C);

 R2(CD);

 R4(D,E)
BOYCE CODD NORMAL FORM
LOSSLESS JOIN
DECOMPOSITION
BOYCE-CODD NORMAL FORM

 BCNF is an extension of Third Normal


Form on strict terms. BCNF states that −
For any non-trivial functional dependency, X
→ A, X must be a super-key.
A relation scheme R is in BCNF if (and only
if) for every non-trivial fd X  Y in F+, X is a
superkey (for R).
EXAMPLE

Consider the relation R(A,B,C,D,E) with FD’s


F = {AB  C, CB, A  D}. Is R in BCNF?
 R has two Keys ABE or ACE

 AB+ ={ABCD} ; AB is not a SK


 C+ = {CB} ;C is no a SK
 A+ = {AD} ; A is not a SK

R is not in BCNF
LOSSLESS JOIN DECOMPOSITION
ALGORITHM FOR BCNF
 Given a universal relation R and a set of functional
dependencies on the attributes of R:
D ←R;
while there is some relation schema S in D that is not
already BCNF
{
Find a functional dependency X→Y in S that violates
BCNF
Replace S by two relation schemas (S-Y) and (X,Y)
}
EXAMPLE

Consider the relation R(A,B,C,D,E) with FD’s


F = {AB  C, CB, A  D}. Is R in BCNF?
 R has two Keys ABE or ACE

 AB+ ={ABCD} ; AB is not a SK


 C+ = {CB} ;C is no a SK
 A+ = {AD} ; A is not a SK

 R is not in BCNF
EXERCISE

1. Let R = {A,B,C} and F = { A  B, C 


B} Why is R not in BCNF. Decompose R
to lossless join BCNF decomposition.
2. R = (A, B, C ) and F = {A →B, B
→C}. Why is R not in BCNF.
Decompose R to lossless join BCNF
decomposition.
NORMALISE THE TABLE BELOW TO BCNF.
INF
Project Project Employee Employee Rate Hourly
Number Name Number Name Category Rate
1023 Harare 11 Chipo A 60
Travel Site Radebe

1023 Harare 12 Pauline B 50


Travel Site Gumbo

1023 Harare 16 Charles C 40


Travel Site Moyo

1056 Online 11 Chipo A 60


Estate Radebe
Agency
1056 Online 17 Tapiwa B 50
Estate Nyika
Agency
FDS
 ProjectNumber ProjectName
 EmployeeNumber EmployeeName

 EmployeeNumber RateCategory

 EmployeeNumberHourlyRate

 RateCategory HourlyRate

SK= ProjectNumber,EmployeeNumber

ProjectEmployeeRate (ProjectNumber, ProjectName,


EmployeeNumber, EmployeeName, RateCategory, HourlyRate)
BCNF RELATIONS
 Project(ProjectNumber, ProjectName)
 Rate (RateCategory, HourlyRate)
 Employee (EmployeeNumber,
EmployeeName, RateCategory)
 ProjectEmployee (ProjectNumber,
EmployeeNumber)
PROJECT (PROJECTNUMBER, PROJECTNAME)
RATE (RATECATEGORY, HOURLYRATE)
EMPLOYEE (EMPLOYEENUMBER,
EMPLOYEENAME, RATECATEGORY)
PROJECTEMPLOYEE (PROJECTNUMBER,
EMPLOYEENUMBER)
QUESTIONS
1. Given R(ABCXZ) and F{AB, CX, BXZ}.
Derive ACZ using Armstrong‘s Axioms.
2. Given F= {AB,CD} with C being a proper subset
of B, show that AD
3. Given Relation r(R) shown. State whether the
following FDs are satisfied by the relation.
a) AB A B C
b) AC 1 4 2
c) ABC 3 5 6
d) CA 3 4 6
e) BCA 7 3 8
f) ACB 9 1 0

You might also like