UNIT II DBMS MCA 23
UNIT II DBMS MCA 23
Contents………………………… Page No
Functional Dependencies and Normalization for Relational Databases
1. Informal Design Guidelines for Relation Schemas 1
2. Functional Dependencies 3
3. 1NF (First Normal Form) 4
4. 2NF (Second Normal Form) 5
5. 3NF (Third Normal Form) 6
6. BCNF (Boyce-Codd Normal Form) 6
Relational Database Design Algorithms and Further Dependencies
7. Properties of Relational Decompositions 7
8. Multivalued dependencies and fourth normal form 9
9. Join Dependencies and Fifth Normal Form 11
0
FUNCTIONAL DEPENDENCIES AND NORMALIZATION FOR RELATIONAL
DATABASES
1. INFORMAL DESIGN GUIDELINES FOR RELATION SCHEMAS
1
2
2. FUNCTIONAL DEPENDENCIES
3
3. FIRST NORMAL FORM (1NF)
Normalization is a technique for dividing relation into relations and identifying anomalies
in the existing relations.
Advantages of Normalization:
Less storage space
Reduces data redundancy in a database
It eliminates serious manipulation anomalies.
4
First Normal Form (1NF):
A relation in which the intersection of each row and column contains one and only one
value.Example:
EmpNum EmpPhone EmpDegrees
111 040-23840112
222 040-23987654 { BA, BSc, PhD }
333 040-23456789 { BSc, MSc }
Transformation into 1NF:
Employee( EmpNum, EmpPhone) EmployeeDegree(EmpNum, EmpDegrees)
EmpNum EmpPhone EmpNum EmpDegrees
111 040-23840112 222 BA
222 040-23987654 222 BSc
333 040-23456789 222 PhD
333 BSc
333 MSc
InvNum InvDate
5
5. THIRD NORMAL FORM (3NF)
Transitive dependency: A condition where A, B, and C are attributes of a relation such that if
A →B and B→C, then C is transitively dependent on A via B.
A relation is in third normal form, if there is no transitive dependency for non-prime attributes as
well as it is in second normal form.
A relation is in 3NF if at least one of the following condition holds in every non-trivial function
dependency X –> Y:
1. X is a super key.
2. Y is a prime attribute (each element of Y is part of some candidate key).
In other words,
A relation that is in First and Second Normal Form and in which no non-primary-key attribute is
transitively dependent on the primary key, then it is in Third Normal Form (3NF).
Note – If A->B and B->C are two FDs then A->C is called transitive dependency.
The normalization of 2NF relations to 3NF involves the removal of transitive dependencies. If a
transitive dependency exists, we remove the transitively dependent attribute(s) from the relation
by placing the attribute(s) in a new relation along with a copy of the determinant.
6
Example:
Note: any relation that is in BCNF, is in 3NF The First Normal Form -The Second Normal Form
- The Third Normal Form - Boyce Codd Normal Form –
1. Attribute Preservation:
Using functional dependencies the algorithms decompose the universal relation schema R in a set of
relation schemas D = { R1, R2, ….. Rn } relational database schema, where ‘D’ is called the
Decomposition of R.
The attributes in R will appear in at least one relation schema Ri in the decomposition, i.e., no
attribute is lost. This is called the Attribute Preservation condition of decomposition.
7
2. Dependency Preserving
If each functional dependency X->Y specified in F appears directly in one of the relation schemas
Ri in the decomposition D or could be inferred from the dependencies that appear in some Ri. This
is the Dependency Preservation.
3. If a decomposition is not dependency preserving some dependency is lost in decomposition. To
check this condition, take the JOIN of 2 or more relations in the decomposition.
For example:
R = (A, B, C)
F = {A ->B, B->C}
Key = {A}
R is not in BCNF.
8
X, Y : decomposition of R,
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 :
Person->-> mobile,
Person ->-> food_likes
9
This is read as “person multi determines mobile” and “person multi determines food_likes.”
Note that a functional dependency is a special case of multivalued dependency. In a functional
dependency X -> Y, every x determines exactly one y, never more than one.
Example: Consider the database table of a class that has two relations R1 contains student ID(SID)
and student name (SNAME) and R2 contains course id(CID) and course name (CNAME).
Table R1
SID SNAME
S1 A
S2 B
Table R2
CID CNAME
C1 C
C2 D
10
Table R1 X R2
SID SNAME CID CNAME
S1 A C1 C
S1 A C2 D
S2 B C1 C
S2 B C2 D
Joint Dependency
Example: Table1
Company Product
C1 Pendrive
C1 mic
C2 speaker
C2 speaker
11
Company->->Product
Table R2
Agent Company
Aman C1
Aman C2
Mohan C1
Agent->->Company
Table R3
Agent Product
Aman Pendrive
Aman Mic
Aman speaker
Mohan speaker
Agent->->Product
Table R1⋈R2⋈R3
C1 Pendrive Aman
C1 mic Aman
C2 speaker speaker
C1 speaker Aman
Agent->->Product
12
Fifth Normal Form / Projected Normal Form (5NF)
A relation R is in Fifth Normal Form if and only if everyone joins dependency in R is implied by
the candidate keys of R. A relation decomposed into two relations must have lossless
join Property, which ensures that no spurious or extra tuples are generated when relations are
reunited through a natural join.
Properties
A relation R is in 5NF if and only if it satisfies the following conditions:
R should be already in 4NF.
It cannot be further non loss decomposed (join dependency).
Example – Consider the above schema, with a case as “if a company makes a product and an
agent is an agent for that company, then he always sells that product for the company”. Under
these circumstances, the ACP table is shown as:
Table ACP
Agent Company Product
A1 PQR Nut
A1 PQR Bolt
A1 XYZ Nut
A1 XYZ Bolt
A2 PQR Nut
The relation ACP is again decomposed into 3 relations. Now, the natural Join of all three relations
will be shown as:
Table R1
Agent Company
A1 PQR
A1 XYZ
A2 PQR
13
Table R2
Agent Product
A1 Nut
A1 Bolt
A2 Nut
Table R3
Company Product
PQR Nut
PQR Bolt
XYZ Nut
XYZ Bolt
The result of the Natural Join of R1 and R3 over ‘Company’ and then the Natural Join of R13 and
R2 over ‘Agent’and ‘Product’ will be Table ACP.
Hence, in this example, all the redundancies are eliminated, and the decomposition of ACP is a
lossless join decomposition. Therefore, the relation is in 5NF as it does not violate the property
of lossless join.
14