0% found this document useful (0 votes)
20 views

Unit 3

The document discusses relational database design and functional dependencies. It defines key concepts like functional dependency, super key, candidate key, closure of attributes and functional dependencies, and canonical cover. It provides examples to illustrate how to determine functional dependencies from a relation, compute attribute closure, identify extraneous attributes and redundant dependencies, and derive the canonical cover for a set of functional dependencies.

Uploaded by

abhivardhan786
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Unit 3

The document discusses relational database design and functional dependencies. It defines key concepts like functional dependency, super key, candidate key, closure of attributes and functional dependencies, and canonical cover. It provides examples to illustrate how to determine functional dependencies from a relation, compute attribute closure, identify extraneous attributes and redundant dependencies, and derive the canonical cover for a set of functional dependencies.

Uploaded by

abhivardhan786
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Database Management System

Unit-3

Dharmendra Kumar(Associate Professor)


Department of Computer Science and Engineering
United College of Engineering and Research, Prayagraj

1
RELATIONAL DATABASE DESIGN

1 Functional dependency
Consider a relation schema R, and let α ⊆ R and β ⊆ R. The functional dependency
α → β holds on relation schema R if, in any legal relation r(R), for all pairs of tuples t1
and t2 in r such that t1 [α] = t2 [α], then t1 [β] = t2 [β] must also satisfy with in r(R).

Super key: A subset α of a relation schema R is said to be super key of R if α → R


holds.

Candidate key: A subset α of a relation schema R is said to be super key of R


if
(1) α should be super key of R i.e. α → R.
(2) There should not exist any proper subset K of α such that K → R.

Example: Consider the following relation :-

A B C D
a1 b1 c1 d1
a1 b2 c1 d2
a2 b2 c2 d2
a2 b2 c2 d3
a3 b3 c2 d4

Find out which functional dependencies are satisfied.

Solution: Observe that A→C is satisfied. There are two tuples that have an A value
of a1 . These tuples have the same C value namely, c1 . Similarly, the two tuples with an
A value of a2 have the same C value, c2 . There are no other pairs of distinct tuples that
have the same A value. The functional dependency C → A is not satisfied, however. To
see that it is not, consider the tuples t1 = (a2 , b3 , c2 , d3 ) and t2 = (a3 , b3 , c2 , d4 ). These
two tuples have the same C values, c2 , but they have different A values, a2 and a3 , re-
spectively. Thus, we have found a pair of tuples t1 and t2 such that t1 [C] = t2 [C], but
t1 [A] 6= t2 [A].
Some other functional dependencies which satisfied are the following:-
AB → C, D → B, BC → A, CD → A, CD → B, AD → B, AD → C.

1.1 Trivial functional dependency


A functional dependency α → β is said to be trivial if β ⊆ α.

2
Some trivial functional dependencies are the following:- ABC → C, CD → C, A →
A.

1.2 Closure of a Set of Functional Dependencies


Consider F is a set of functional dependencies defined on relation schema R.
Closure of F is the set of all the functional dependencies which are logically implied(or
derived) from F. It is denoted by F + .

1.3 Armstrong’s axioms


Following three rules are said to be Armstrong’s axioms.

• Reflexivity rule: If α is a set of attributes and β ⊆ α, then α → β holds.

• Augmentation rule: If α → β holds and γ is a set of attributes, then γα → γβ


holds.

• Transitivity rule: If α → β holds and β → γ holds, then α → γ holds.

Some additional rules are the following:-

• Union rule: If α → β and α → γ holds, then α → βγ holds.

• Decomposition rule: If α → βγ holds then α → β and α → γ holds.

• Pseudo transitivity rule: If α → β holds and γβ → δ holds, then γα → δ


holds.

Example: Consider relation schema R = (A, B, C, G, H, I) and the set F of functional


dependencies A → B, A → C, CG → H, CG → I, B → H. We list several members of
F+ here:

• A → H. Since A → B and B → H hold, we apply the transitivity rule.

• CG → HI . Since CG → H and CG → I , the union rule implies that CG → HI.

• AG → I. Since A → C and CG → I, the pseudo transitivity rule implies that AG


→ I holds.

Algorithm to compute F + using Armstrong’s axioms


In this algorithm, the input will be F and R. It is computed by following algorithm:-
Note: The left-hand and right-hand sides of a functional dependency are both subsets
of R. Since a set of size n has 2n subsets, therefore there are a total of 2 × 2n = 2n+1
possible functional dependencies, where n is the number of attributes in R. [h] F and R
F+ F+ ← F
F + does not change any further for each functional dependency f in F + apply reflexivity
and augmentation rules on f
add the resulting functional dependencies to F + each pair of functional dependencies
f1 and f2 in F + f1 and f2 can be combined using transitivity rule add the resulting
functional dependency to F + A procedure to compute F+

3
1.4 Closure of attribute sets
Consider relation schema R and a set of functional dependencies F. Let α ⊆ R.
The closure of α is the set of all the attributes of R which are logically determined by α
under a set F. It is denoted by α+ .
The closure of α is computed by following algorithm:- α and F α+ = result result ← α
changes to result each functional dependency β → γ in F β ⊆ result result ← result ∪ γ
An algorithm to compute α+ , the closure of α under F
Example: Consider relation schema R = (A, B, C, G, H, I) and the set F of functional
dependencies A → B, A → C, CG → H, CG → I, B → H. Compute the closure of {A,G},
{C,G} and {A}.
Solution:
{A, G}+ = {A,G}
= {A,B,C,G}
= {A,B,C,G,H,I}
Therefore, {A, G}+ = {A,B,C,G,H,I}
{C, G}+ = {C,G}
= {C,G,H,I}
Therefore, {C, G}+ = {C,G,H,I}
{A}+ = {A}
= {A,B,C}
= {A,B,C,H}
Therefore, {A}+ = {A,B,C,H}
Uses or applications of attribute closure
There are several uses of the attribute closure:

• To test if α is a superkey, we compute α+ , and check if α+ contains all attributes


of R.

• We can check if a functional dependency α → β holds by checking if β ⊆ α+ .

• It gives us an alternative way to compute F + : For each γ ⊆ R, we find the closure


γ + , and for each S ⊆ γ + , we output a functional dependency γ → S.

1.5 Canonical Cover


Before defining canonical cover, first we are going to define some concepts related with
it.
Extraneous attribute: Consider a set F of functional dependencies and the functional
dependency α → β in F.

• Attribute A is said to be extraneous in α if A ∈ α, and F logically implies (F -


{α → β}) ∪ {(α − A) → β}.

• Attribute A is said to be extraneous in β if A ∈ β, and the set of functional


dependencies (F - {α → β}) ∪ {α → (β − A)} logically implies F.

Example: Consider F = { AB → C and A → C}. Find extraneous attributes in F.


Solution: Consider the functional dependency AB → C. In this dependency, right hand
side contains single attribute, therefore right hand side has no extraneous attribute.
Now, consider left hand side. Now, we check A is extraneous attribute or not.

4
Eliminate A from FD, AB → C. We get B → C. Clearly, B → C can not be derived from
F, therefore A is not extraneous attribute.
Now, we check B is extraneous attribute or not.
Eliminate B from FD, AB → C. We get A → C. Clearly, A → C is derived from F,
therefore B is an extraneous attribute.
Consider the functional dependency A → C. In this dependency, left hand and right hand
side contains single attribute, therefore this FD has no extraneous attribute.

Example: Consider F = {AB → CD and A → C}. Find extraneous attributes in


F.
Solution: Consider the functional dependency AB → CD. In this FD, both sides may
contain extraneous attributes.
Now, consider left hand side. Now, we check A is extraneous attribute or not.
Eliminate A from FD, AB → CD. We get B → CD. Clearly, B → CD can not be derived
from F, therefore A is not extraneous attribute.
Now, we check B is extraneous attribute or not.
Eliminate B from FD, AB → CD. We get A → CD. Clearly, A → CD can not be derived
from F, therefore B is not extraneous attribute.
Now, we check C is extraneous attribute or not.
Eliminate C from FD, AB → CD. We get AB → D. Clearly, Set F’ = {AB → D, A →
C} derives set F, therefore C is an extraneous attribute.
Now, we check D is extraneous attribute or not.
Eliminate D from FD, AB → CD. We get AB → C. Clearly, Set F’ = {AB → C, A →
C} can not derive set F, therefore D is not an extraneous attribute.
Consider the functional dependency A → C. In this dependency, left hand and right hand
side contains single attribute, therefore this FD has no extraneous attribute.

Redundant functional dependency A functional dependency α → β in F is said


to be redundant if after eliminating α → β from F, we get a set of functional dependency
F’ equivalent to F. That is, F + = F 0+ .
Example: Consider F = {A → B, B → C, and A → C}. In this set F, FD A → C} is
redundant because it is derived from A → B and B → C using transitivity rule.

Canonical Cover:
Canonical cover is defined for a set F of functional dependencies.
Canonical cover of F is the minimal set of functional dependencies equivalent to F that is
canonical cover is a set of functional dependencies equivalent to F which does not contain
any extraneous attribute and redundant FD. It is denoted by Fc .
A canonical cover for a set of functional dependencies F can be computed by following
algorithm.
[h] F Fc Fc ← F
Fc does not change any further Use the union rule to replace any dependencies in Fc of
the form α1 → β1 and α1 → β2 with α1 → β1 β2 .
Find a functional dependency α → β in Fc with an extraneous attribute either in α or in
β.
/* Note: the test for extraneous attributes is done using Fc , not F */
If an extraneous attribute is found, delete it from α → β.
Computing canonical cover

5
Example: Consider the following set F of functional dependencies on relation schema
R = (A,B,C):
A → BC
B→C
A→B
AB → C
Compute the canonical cover for F.
Solution:

• There are two functional dependencies with the same set of attributes on the left
side of the arrow:
A → BC, A → B
We combine these functional dependencies using union rule into A → BC.

• A is extraneous in AB → C because F logically implies (F - {AB → C}) ∪ {B


→ C}. This assertion is true because B → C is already in our set of functional
dependencies.

• C is extraneous in A → BC, since A → BC is logically implied by A → B and B


→ C.

Thus, canonical cover of F is


Fc = {A → B, B → C}.

Note: A canonical cover might not be unique.

Example: Consider the following set F of functional dependencies on relation schema


R = (A,B,C):
A → BC
B → AC
C → AB
Compute the canonical cover for F.
Solution: If we apply the extraneity test to A BC, we find that both B and C are
extraneous under F. However, it is incorrect to delete both. The algorithm for finding
the canonical cover picks one of the two, and deletes it. Then,

1. If C is deleted, we get the set F’ = {A → B, B → AC, and C → AB}. Now, B is


not extraneous in the right hand side of A → B under F’. Continuing the algorithm,
we find A and B are extraneous in the right hand side of C → AB, leading to two
canonical covers
Fc = {A → B, B → C, and C → A}, and
Fc = {A → B, B → AC, and C → B}.

2. If B is deleted, we get the set F’ = {A → C, B → AC, and C → AB}. This case is


symmetrical to the previous case, leading to the canonical covers
Fc = {A → C, C → B, and B → A}, and
Fc = {A → C, B → C, and C → AB}.

6
1.6 Decomposition
Let R be a relation schema. A set of relation schemas {R1 , R2 , ..., Rn } is a decomposition
of R if
R = R1 ∪ R2 ∪ ............... ∪ Rn
That is, {R1 , R2 , ..., Rn } is a decomposition of R if, for i = 1, 2, . . . , n, each Ri is a
subset of R, and every attribute in R appears in at least one Ri .
Let r be a relation on schema R, and let ri = ΠRi (r) for i = 1, 2, . . . , n. That is,
{r1 , r2 , ..., rn } is the database that results from decomposing R into {R1 , R2 , ..., Rn }. It
is always the case that
r ⊆ r1 ./ r2 ./ ∆∆∆ ./ rn .
A decomposition {R1 , R2 , ..., Rn } of R is a lossless-join decomposition if, for all relations
r on schema R,
r = ΠR1 (r) ./ ΠR2 (r) ./ ..................... ./ ΠRn (r)...........(1)
If equation (1) is not satisfied, then this decomposition is said to be lossy decomposition.

1.7 Desirable Properties of Decomposition


Lossless-Join Decomposition
Let R be a relation schema, and let F be a set of functional dependencies on R. Let R1
and R2 form a decomposition of R. This decomposition is a lossless-join decomposition
of R if at least one of the following functional dependencies is in F+:

• R1 ∩ R2 → R1

• R1 ∩ R2 → R2

In other words, if R1 ∩ R2 forms a superkey of either R1 or R2 , then the decomposition


of R is a lossless-join decomposition.
Eample: Consider the following schema R and F.
R = (branch-name, branch-city, assets, customer-name, loan-number, amount)
F is the following :-
branch-name → branch-city assets
loan-number → amount branch-name
R is decomposed into following relation schemas:-
Branch-schema = (branch-name, branch-city, assets)
Loan-info-schema = (branch-name, customer-name, loan-number, amount)
Is this decomposition lossless or lossy?
Solution:
Branch-schema ∩ Loan-info-schema = {branch-name}
Clearly, branch-name is a super key of Branch-schema. Therefore this decomposition is
lossless.

Dependency Preservation
Let F be a set of functional dependencies on a schema R, and let R1 , R2 , ..., Rn be a decom-
position of R. Let F1 , F2 , ..., Fn is the set of dependencies corresponding to R1 , R2 , ..., Rn .
Let F’ = F1 ∪ F2 ∪ ... ∪ Fn
If F’ = F, then the decomposition will be functionally dependency preserve.
If F’ 6= F , then the decomposition may or may not be functionally dependency preserve.

7
In this case, compute F + and F 0+ . If F + = F 0+ , then the decomposition will be func-
tionally dependency preserve otherwise not.

Eample: Consider the following schema R and F.


R = (branch-name, branch-city, assets, customer-name, loan-number, amount)
F is the following :-
branch-name → branch-city assets
loan-number → amount branch-name
R is decomposed into following relation schemas:-
Branch-schema = (branch-name, branch-city, assets)
Loan-info-schema = (branch-name, customer-name, loan-number, amount)
Is this decomposition functionally dependency preserve?
Solution:
Let F1 and F2 are the set of functional dependencies corresponding to Branch-schema
and Loan-info-schema respectively. Therefore
F1 = { branch-name → branch-city assets} and
F2 = { loan-number → amount branch-name}
Now, F’ = F1 ∪F2 = {branch-name → branch-city assets, loan-number → amount branch-
name}
Clearly, F’ = F. Therefore this decomposition is functionally dependency preserve.

2 Normalization
Normalization is a database design technique that reduces data redundancy and elimi-
nates undesirable characteristics like Insertion, Update and Deletion Anomalies. Normal-
ization rules divides larger tables into smaller tables and links them using relationships.
The purpose of Normalization is to eliminate redundant (repetitive) data and ensure data
is stored logically.

2.1 Anomalies in DBMS


Anomalies are problems that can occur in poorly planned, unnormalized databases where
all the data is stored in one table (a flatfile database). There are three types of anomalies
that occur when the database is not normalized. These are – insertion, update and
deletion anomaly. Let’s take an example to understand this. Consider a relation Emp-
Dept.

Insertion anomaly: Let us assume that a new department has been started by the
organization but initially there is no employee appointed for that department, then the
tuple for this department cannot be inserted into this table as the E# will have NULL,
which is not allowed as E# is primary key.
This kind of a problem in the relation where some tuple cannot be inserted is known as
insertion anomaly.

Deletion anomaly:
Now consider there is only one employee in some department and that employee leaves
the organization, then the tuple of that employee has to be deleted from the table, but
in addition to that the information about the department also will get deleted.

8
E# Ename Address D# Dname Dmgr#
123456789 Akhilesh Ghaziabad 5 Research 333445555
333445555 Ajay Kanpur 5 Research 333445555
999887777 Shreya Lucknow 4 Administration 987654321
987654321 Sanjay Mirjapur 4 Administration 987654321
666884444 Om Prakash Lucknow 5 Research 333445555
453453453 Manish Delhi 5 Research 333445555
987987987 Ishani Prayagraj 4 Administration 987654321
888665555 Garvita Prayagraj 1 Headquarters 888665555

Table 1: Emp-Dept

This kind of a problem in the relation where deletion of some tuples can lead to loss of
some other data not intended to be removed is known as deletion anomaly.

Modification/update anomaly:
Suppose the manager of a department has changed, this requires that the Dmgr# in all
the tuples corresponding to that department must be changed to reflect the new status.
If we fail to update all the tuples of the given department, then two different records
of employee working in the same department might show different Dmgr# leading to
inconsistency in the database.
This is known as modification/update anomaly.

2.2 Normalization
To overcome these anomalies we need to normalize the data. In the next section we will
discuss different types of normal forms. These normal forms are:-

1. First normal form(1NF)

2. Second normal form(2NF)

3. Third normal form(3NF)

4. Boyce-Codd normal form(BCNF)

5. Fourth normal form(4NF)

6. Fifth normal form(5NF)


First normal form(1NF):
As per the rule of first normal form, an attribute (column) of a table cannot hold multiple
values. It should hold only atomic values.
Consider the following table:-
This table is not in 1NF as the rule says “each attribute of a table must have atomic
(single) values”, the emp mobile values for employees Jon & Lester violates that rule.
To make the table complies with 1NF we should have the data like this:
Now this table is in 1NF.

Second normal form(2NF)

9
emp id emp name emp address emp mobile
101 Herschel New Delhi 8912312390
102 Jon Kanpur 8812121212 , 9900012222
103 Ron Chennai 7778881212
104 Lester Bangalore 9990000123 , 8123450987

Table 2: Employee

emp id emp name emp address emp mobile


101 Herschel New Delhi 8912312390
102 Jon Kanpur 8812121212
102 Jon Kanpur 9900012222
103 Ron Chennai 7778881212
104 Lester Bangalore 9990000123
104 Lester Bangalore 8123450987

Table 3: Revised Employee table

Consider a relation schema R with set of functional dependencies F. A relation schema


R is said to be in second normal form(2NF) if
(1) It is in 1NF.
(2) Every non-prime attribute is fully functionally dependent on candidate key.

Prime attribute An attribute which is a part of any candidate key is said to be prime
attribute. And which is not part of any candidate key is said to be non-prime attribute.

Example: Consider a relation schema R = (A,B,C,D) with only one candidate key
as {A,B}. In this case, A and B are prime attributes. C and D are non-prime attributes.

Partial functional dependent


A partial dependency means if the non-key attributes depend on the part of candidate
key then it is said to be partial dependency.
An attribute is fully functional dependent on a set of attributes α, if it is functionally
dependent on only α and not on any of its proper subset.

Note: A relation with a single-attribute primary key is automatically in at least 2NF.

Example: Consider following functional dependencies in relation R(A, B, C, D)


AB → C
BC → D
Is this relation in 2NF?
Solution:
First find candidate keys. Here candidate key is A,B. Clearly non-prime attributes are C
and D. From functional dependencies, C and D are fully functional dependent, therefore
R is in 2NF.

Example: Consider a relation- R ( V , W , X , Y , Z ) with functional dependencies-


VW → XY

10
Y→V
WX → YZ
Is this relation in 2NF?
Solution:
Here candidate keys are VW, WX and WY. Therefore non-prime attributes are Z. Clearly
Z is fully dependent on candidate keys. Therefore R is in 2NF.

Example: Consider relation R(A, B, C, D, E) with set of following functional depen-


dencies
A → BC,
CD → E,
B → D,
E→A
Is this relation in 2NF?
Solution:
Here candidate keys are A, E, CD, BC. Clearly all the attributes belong into some can-
didate keys, therefore no non-prime attribute. Therefore, R is in 2NF.

Third normal form(3NF)


A relation schema R is in third normal form (3NF) with respect to a set F of functional
dependencies if, for all functional dependencies in F + of the form α → β, where α ⊆ R
and β ⊆ R, at least one of the following holds:
• α → β is a trivial functional dependency.

• α is a super key for R.

• Each attribute A in β − α is contained in a candidate key for R.


In other words, we can define 3NF as following:-
A relation schema R with set of functional dependencies F is said to in 3NF if
(1) It is in 2NF.
(2) No non-prime attribute transitively depends on any candidate key.

Example: Consider a relation- R ( V , W , X , Y , Z ) with functional dependencies-


VW → XY
Y→V
WX → YZ
Is this relation in 3NF?
Solution:
Here candidate keys are VW, WX and WY. Therefore non-prime attributes are Z. Clearly
Z is fully dependent on candidate keys. Therefore R is in 2NF.
Now, Z is not transitively dependent on any candidate key. Therefore, it is in 3NF.

Example: Consider relation R(A, B, C, D, E) with set of following functional depen-


dencies
A → BC,
C → E,
B → D,
Is this relation in 3NF?

11
Solution:
Here candidate key is A. Therefore, non-prime attributes are B, C, D, E. Since candidate
key contains single attribute, therefore R is in 2NF.
Now, Clearly attributes D and E are transitively dependent on candidate key A, therefore
R is not in 3NF.

Example: The relation schema Student Performance (name, courseNo, rollNo, grade)
has the following FDs:
name,courseNo → grade
rollNo,courseNo → grade
name → rollNo
rollNo → name
Is this relation in 3NF?
Solution:
Here candidate keys are {name, courseNo} and {rollNo, courseNo}. Therefore non-prime
attributes are grade. Clearly, grade is fully functional dependent on candidate keys,
therefore this relation schema is in 2NF.
Now, clearly grade is not transitively dependent on candidate keys, therefore this relation
schema is in 3NF.

Boyce-codd normal form (BCNF)


A relation schema R is in BCNF with respect to a set F of functional dependencies if, for
all functional dependencies in F + of the form α → β, where α ⊆ R and β ⊆ R, at least
one of the following holds:

• α → β is a trivial functional dependency.

• α is a super key for R.

Example: The relation schema Student Performance (name, courseNo, rollNo, grade)
has the following FDs:
name,courseNo → grade
rollNo,courseNo → grade
name → rollNo
rollNo → name
Is this relation in BCNF?
Solution:
Consider FD, name,courseNo → grade. Clearly, {name, courseNo} is a super key, there-
fore this satisfy 2nd criteria of BCNF.
Consider FD, rollNo,courseNo → grade. Clearly, {rollNo, courseNo} is a super key, there-
fore this satisfy 2nd criteria of BCNF.
Consider FD, name → rollNo. Clearly, this functional dependency not satisfy any condi-
tion of BCNF. Therefore, this is not in BCNF.

Example: Consider the following relation schemas and their respective functional de-
pendencies:
Customer = (customer-name, customer-street, customer-city)
customer-name → customer-street, customer-city
Branch = (branch-name, assets, branch-city)

12
branch-name → assets, branch-city
Loan = (branch-name, customer-name, loan-number, amount)
loan-number → amount, branch-name

Clearly, Customer and Branch schema are in BCNF, because left side of functional de-
pendency customer-name → customer-street, customer-city and branch-name
→ assets, branch-city is super key.
But Loan schema is not in BCNF, because left side of functional dependency loan-
number → amount, branch-name is not super key and this functional dependency is
also not trivial.

2.3 Decomposition into Normal form


Decomposition into 2NF
Example:
Let R = { A, B, C, D} and F = { AB → C, B → D }.
Is this relation schema in 2NF? If not then decompose it into 2NF.
Solution:
Here, Primary key = {A,B}.
Clearly, this is not in 2NF because partial dependency holds.
Now, we decompose R into R1 and R2 as the following:-
R1 = (A, B, C), F1 = {AB → C}
R2 = (B, D), F2 = {B → D}
Now, R1 and R2 are in 2NF.

Example:
Student-course-info(Name, Course, Grade, Phone-no, Major, Course-dept)
F = { Name → Phone-no Major, Course → Course-dept, Name Course → Grade }
Is this relation schema in 2NF? If not then decompose it into 2NF.
Solution:
Here, Primary key = {Name,Course}.
Clearly, this is not in 2NF because partial dependency holds.
Now, we decompose R into R1 , R2 and R3 as the following:-
R1 = (Name, Phone-no, Major), F1 = {Name → Phone-no Major}
R2 = (Course, Course-dept), F2 = {Course → Course-dept}
R3 = (Name, Course, Grade), F3 = {Name Course → Grade}
Now, R1 , R2 and R3 are in 3NF.

Decomposition into 3NF


Example:
Let R = { A, B, C, D} and F = { A → B, A → C, B → D }.
Is this relation schema in 3NF? If not then decompose it into 3NF.
Solution:
Here, Primary key = {A}.
Clearly, this is not in 3NF because transitivity dependency holds.
Now, we decompose R into R1 and R2 as the following:-
R1 = (A, B, C), F1 = {A → B, A → C}
R2 = (B, D), F2 = {B → D}

13
Now, R1 and R2 are in 3NF.

Example:
Let Banker-info = { branch-name, customer-name, banker-name, office-number} and F =
{ banker-name → branch-name office-number, customer-name branch-name → banker-
name}.
Is this relation schema in 3NF? If not then decompose it into 3NF.
Solution:
Here, Primary key = {customer-name, branch-name}.
Clearly, this is not in 3NF because transitivity dependency holds.
Now, we decompose relation Banker-info into R1 and R2 as the following:-
R1 = (banker-name, branch-name, office-number), F1 = {banker-name → branch-name
office-number}
R2 = (customer-name, branch-name, banker-name), F2 = {customer-name branch-name
→ banker-name}
Now, R1 and R2 are in 3NF.

Decomposition into BCNF


If R is not in BCNF, we can decompose R into a collection of BCNF schemas R1 , R2 , ..., Rn
by the algorithm. The decomposition that the algorithm generates is not only in BCNF,
but is also a lossless-join decomposition.
R and F result result ← R
done = false
compute F +
not done
(there is a schema Ri in result that is not in BCNF) let α → β be a nontrivial func-
tional dependency that holds on Ri such that α → Ri is not in F + , and α ∩ β = φ
result ← (result − Ri ) ∪ (Ri − β) ∪ (α, β)
done = true BCNF decomposition algorithm
Example:
Consider the following schema:-
Lending-schema = ( branch-name, branch-city, assets, customer-name, loan-number,
amount)
F = { branch-name → assets branch-city, loan-number → amount branch-name}
Is this relation schema in BCNF? If not then decompose it into BCNF.
Solution:
Here, Primary key = {customer-name, loan-number}.
Clearly, this is not in BCNF.
Now, we decompose relation Lending-schema into R1 and R2 as the following:-
R1 = ( customer-name, loan-number, amount, branch-name)
F1 = { loan-number → amount branch-name}
R2 = ( branch-name, assets, branch-city)
F2 = { branch-name → assets branch-city}
Clearly, R1 is not in BCNF. Therefore, we again decompose R1 .
Now, we decompose relation R1 into R3 and R4 as the following:-
R3 = ( customer-name, loan-number)
F3 = φ
R4 = (loan-number, amount, branch-name)

14
F4 = { loan-number → amount branch-name}
Now, the final relation schema are R2 , R3 and R4 . All these are in BCNF.

2.4 Algorithm to check if a decomposition is lossless


Input: A relation schema R(A1 , A2 , ............., An ) and a decomposition D = {R1 , R2 , ............., Rm }
and a set F of functional dependencies.

1. Create a matrix S with one row i for each relation Ri in D, and one column j for
each attribute aj in R.

2. Set S(i,j) = aj , if relation schema Ri contains attribute Aj otherwise set S(i,j) =


bij .

3. . change ← true
(change) each functional dependency α → β in F (row i and j exists such that
the same symbol appears in each column corresponding to attribute in α) one of
the symbols in the β column is ar Make other symbol to be ar the symbols are bpk
and bqk Make both of them bpk change = false

4. If there exists a row in which all the symbols are a’s, then the decomposition has
the lossless. Otherwise decomposition has lossy.

Example:
Consider the following schema:-
R=(SSN, Ename, Pnumber, Pname, Plocation, Hours)
F= { SSN → Ename, Pnumber → Pname Plocation, SSN pnumber → Hours }
R1 = (SSN, Ename)
R2 = (Pnumber, Pname, Plocation)
R3 = (SSN, Pnumber, Hours)
Find out decomposition of R in R1 , R2 , R3 is lossless or lossy.
Solution:
First construct matrix. It will be order of 3×6.
The initialization table will be the following:-
After the first iteration , the table will be the following:- After the second iteration,
the table will not changed. Therefore, the above table is the final table.
Since in this table, row 3 contains only a’s symbol, therefore this decomposition is lossless.

Example:
Consider the following schema:-
R=(A, B, C, D, E)
F= { AB → CD, A → E, C → D }
R1 = (A, B, C)
R2 = (B, C, D)
R3 = (C, D, E)
Is the decomposition of R in R1 , R2 , R3 is lossless or lossy?
Solution:
First construct matrix. It will be order of 3×5.
The initialization table will be the following:- After the first iteration , the table will
be the following:- After the second iteration, the table will not changed. Therefore, the

15
above table is the final table.
Since in this table, no row contains only a’s symbol, therefore this decomposition is lossy.

3 Multivalued dependency
Let R be a relation schema and let α ⊆ R and β ⊆ R. The multivalued dependency
α →→ β holds on R if in any legal relation r(R), for all pairs of t1 and t2 in r such that
t1 [α] = t2 [α], there exists two tuples t3 and t4 in r such that
t1 [α] = t2 [α] = t3 [α] = t4 [α]
t3 [β] = t1 [β]
t4 [β] = t1 [β]
t3 [R − β] = t2 [R − β]
t4 [R − β] = t1 [R − β]

3.1 Trivial multivalued dependency


A multivalued dependency α →→ β is said to be trivial if β ⊆ α or β ∪ α = R.

Note: If α → β, then α →→ β. That is, every functional dependency is also a


multivalued dependency.

Example: Consider the following relation schema.


In this table, multivalued dependency
customer-name →→ customer-street customer-city
holds.

3.2 Axioms for Multivalued dependency


(1) Replication rule:
X → Y ⇒ X →→ Y
(2) Reflexivity rule:
X →→ X
(3) Augmentation rule:
X →→ Y ⇒ XZ →→ Y
(4) Union rule:
X →→ Y and X →→ Z ⇒ X →→ Y Z
(5) Complementation rule:
X →→ Y ⇒ X →→ (R − X − Y )
(6) Transitivity rule:
X →→ Y and Y →→ Z ⇒ X →→ (Z − Y )
(7) Intersection rule:
X →→ Y and X →→ Z ⇒ X →→ (Y ∩ Z)
(8) Difference rule:
X →→ Y and X →→ Z ⇒ X →→ (Y − Z) and X →→ (Z − Y )
(9) Pseudo transitivity rule:

16
X →→ Y and XY →→ Z ⇒ X →→ (Z − Y )
(10) Coalescence rule:
Given that W ⊆ Y and Y ∩ Z = φ, and if X →→ Y and Z → W then X → W .

3.3 Closure under Multivalued dependency


Let D be the set of functional and multivalued dependencies.
The closure of D is the set of all functional and multivalued dependencies that are logi-
cally implied by D. It is denoted by D+ .

Example: Consider R = (A, B, C, G, H, I)


and F ={A →→ B, B →→ HI, CG → H}
Find some members of D+ .
Solution: Some members of D+ are the following:-

• A →→ CGHI, By complementation rule in A →→ B

• A →→ HI, By transitivity rule in A →→ B and B →→ HI

• B → H, By coalescence rule in B →→ HI and CG → H

• A →→ CG, By difference rule in A →→ CGHI and A →→ HI.

4 Fourth Normal Form(4NF)


A relation schema R is in fourth normal form(4NF) with respect to a set D of functional
and multivalued dependencies if, for all multivalued dependencies in D+ of the form
α →→ β, where α ⊆ R and β ⊆ R, at least one of the following holds:

• α →→ β is a trivial multivalued dependency.

• α is a super key for schema R.

Note: Every 4NF schema is in BCNF.

4.1 Decomposition in to 4NF


Following algorithm is used to decompose schema R into 4NF. Relation schema R and
set D R1 , R2 , ..., Rm result ← R
done=false
Compute D+
not done
(there is a schema Ri in result that is not in 4NF w.r.t. Di ) let α →→ β be a
nontrivial multivalued dependency that holds on Ri such that α → Ri is not in Di , and
α∩β =φ
result ← (result − Ri ) ∪ (Ri − β) ∪ (α, β)
done = true BCNF decomposition algorithm Example: Consider the following relation

17
SSN Ename Pnumber Pname Plocation Hours
R1 a1 a2 b13 b14 b15 b16
R2 b21 b22 a3 a4 a5 b26
R3 a1 b32 a3 b34 b35 a6

SSN Ename Pnumber Pname Plocation Hours


R1 a1 a2 b13 b14 b15 b16
R2 b21 b22 a3 a4 a5 b26
R3 a1 a2 a3 a4 a5 a6

A B C D E
R1 a1 a2 a3 b14 b15
R2 b21 a2 a3 a4 b25
R3 b31 b32 a3 a4 a5

A B C D E
R1 a1 a2 a3 a4 b15
R2 b21 a2 a3 a4 b25
R3 b31 b32 a3 a4 a5

loan-number customer-name customer-street customer-city


L-23 Smith North Rye
L-23 Smith Main Manchester
L-93 Curry Lake Horseneck

loan-number customer-name customer-street customer-city


L-23 Smith North Rye
L-23 Smith Main Manchester
L-93 Curry Lake Horseneck

18
schema. Find out this table is in 4NF or not. If not, then decompose it into 4NF.
Solution: In this table, multivalued dependency
customer-name →→ customer-street customer-city
holds.
Clearly, neither this multivalued dependency is trivial nor customer-name is super key.
Therefore, this table is not in 4NF.
By using above algorithm, this table is decomposed as
R1 = (customer-name, loan-number)
R2 = (customer-name, customer-street, customer-city)
Now, R1 and R2 are in 4NF.

5 Join dependency
Given a relation schema R. let R1 , R2 , ..........., Rn are the projections of R. A relation
r(R) satisfies the join dependency *(R1 , R2 , ..........., Rn ), iff the join of the projection of
r on Ri , 1 ≤ i ≤ n, is equal to r.
r = ΠR1 ./ ΠR2 ./ ΠR3 ./ ......... ./ ΠRn

5.1 Trivial join dependency


A join dependency is trivial if one of the projections of R is R itself.

5.2 Project join normal form(PJNF) or 5NF


Consider a relation schema R and D is the set of functional, multivalued and join depen-
dencies.
The relation R is in Project join normal form with respect to D if for every join depen-
dency *(R1 , R2 , ..........., Rn ), either of the following holds:-
(i) The join dependency is trivial.
(ii) Every Ri is a super key of R.

5.3 Exercise
1. Consider R = (A, B, C, D, E, F, G) and
F= {A → B, BC → F , BD → EG, AD → C, D → F , BEG → F A}
Calculate the following:-
(a) (A)+
(b) (ACEG)+
(c) (BD)+

2. Consider R = (A, B, C, D, E) and


F= {A → B, BC → E, ED → A}
(a) List all the candidate keys for R.
(b) Is R in third normal form?
(c) Is R in BCNF?

3. Consider R = (A, B, C, D, E, F) and


F= {AB → C, C → B, ABD → E, AD → C, F → A}

19
The decomposition of R is
D={R1 (B, C), R2 (A, C), R3 (A, B, D, E), R4 (A, B, D, F )}
Check whether the decomposition is lossless or lossy.

4. Consider R = (V, W, X, Y, Z) and


F= {Z → V , W → Y , XY → Z, V → W X}
Sate whether the following decomposition of schema R is lossless join decomposition.
Justify your answer.
(i) R1 = (V,W,X) and R2 = (V,Y,Z)
(ii) R1 = (V,W,X) and R2 = (X,Y,Z)

5. Consider R = (A, B, C, D, E, F, G, H, I, J) and


F= {AB → C, A → DE, B → F , F → GH, D → IJ}
Is R in 2NF? If not, then decompose it into 2NF.

6. Consider R = (A, B, C, D, E) and


F= {A → BC, CD → E, B → D, E → A}
(i) List all the candidate keys for R.
(ii) Compute the canonical cover.

7. Consider R = (A, B, C, D, E) and


F= {A →→ BC, B →→ CD, E →→ AD}
Is R in 4NF? If not, then decompose it into 4NF.

8. Consider R = (A, B, C, D, E, F, G, H) and


F= {AB → C, BC → D, E → F , G → F , H → A, F G → H }
Is the decomposition of R into R1 (A, B, C, D), R2 (A, B, C, E, F ), R3 (A, D, F, G, H)
lossless? Is it dependency preserving?

9. Define partial functional dependency. Consider the following two sets of functional
dependencies F = A →C, AC →D, E →AD, E →H and G = A →CD, E →AH.
Check whether or not they are equivalent.

10. Define Minimal Cover. Suppose a relation R (A,B,C) has FD set F = A → B, B


→C, A → C, AB → B, AB → C, AC → B convert this FD set into minimal cover.

11. Write the difference between 3NF and BCNF. Find normal form of relation R(A,B,C,D,E)
having FD set F= A→B,BC→E,ED→A.

6 AKTU Examination Questions


1. Explain normalization. What is normal form?

2. Describe Multivalued dependency.

3. What are the different types of anomalies associated with database?

4. Why do we normalize database?

5. Define partial functional dependency. Consider the following two sets of functional
dependencies F = A →C, AC →D, E →AD, E →H and G = A →CD, E →AH.
Check whether or not they are equivalent.

20
6. Define Minimal Cover. Suppose a relation R (A,B,C) has FD set F = A → B, B
→C, A → C, AB → B, AB → C, AC → B convert this FD set into minimal cover.

7. Write the difference between 3NF and BCNF. Find normal form of relation R(A,B,C,D,E)
having FD set F= A→B,BC→E,ED→A.

8. Define 2 NF.

9. Write difference between BCNF Vs 3 NF.

10. Short Notes of the Following


(i)MVD or JD
(ii) Normalization with advantages

11. Explain 1NF, 2NF, 3NF and BCNF with suitable example.

12. Consider the universal relation schema R = (A, B, C, D, E, F, G, H, I, J) and


F= {AB → C, A → DE, B → F , F → GH, D → IJ}
Determine the keys for R? Decompose R into 2NF.

13. Distinguish between functional dependency and multivalued dependency.

14. Define functional dependency. What do you mean by lossless decomposition ?


Explain with suitable example how function dependencies can be used to show that
decomposition is lossless.

7 Gate questions
1. From the following instance of a relation schema R(A,B,C), we can conclude that

A B C
1 1 1
1 1 0
2 3 2
2 3 2

(a) A functionally determines B and B functionally determines C


(b) A functionally determines B and B does not functionally determines C
(c) B does not functionally determines C
(d) A does not functionally determines B and B does not functionally determines
C

2. Consider the following functional dependencies in a database.


Date of birth → Age, Age → Eligibility
Name → Roll number, Roll number → Name
Course number → Course name, Course number → Instructor
(Roll number, Course number) → grade

21
The relation (Roll number, Name, Date of birth, Age) is in
(a) Second normal form but not in third normal form
(b) Third normal form but not in BCNF
(c) BCNF
(d) None of the above

3. The relation schema student performance (name, courseNo, rollNo, grade) has the
following functional dependencies:-
(name, courseNo) → grade
(rollNo, courseNo) → grade
name → rollNo
rollNo → name

The highest normal form of this relation schema is


(a) 2NF (b) 3NF (c) BCNF (d) 4NF

22

You might also like