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

Normalization: Compiled by Samiksha Singla

Normalization is the process of organizing data in a database to minimize redundancy and dependency. It involves splitting tables into multiple tables and linking them together through primary keys. There are various normal forms that organize data to different degrees, from 1NF to 5NF. Higher normal forms have fewer anomalies and dependencies but may require more joins to retrieve related data. Normalization improves data integrity, storage efficiency, and scalability.

Uploaded by

noorie_00183771
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
433 views

Normalization: Compiled by Samiksha Singla

Normalization is the process of organizing data in a database to minimize redundancy and dependency. It involves splitting tables into multiple tables and linking them together through primary keys. There are various normal forms that organize data to different degrees, from 1NF to 5NF. Higher normal forms have fewer anomalies and dependencies but may require more joins to retrieve related data. Normalization improves data integrity, storage efficiency, and scalability.

Uploaded by

noorie_00183771
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Normalization

Compiled by
Samiksha Singla
Database Normalization
Database normalization is the process of removing
redundant data from your tables in to improve storage
efficiency, data integrity, and scalability.
In the relational model, methods exist for quantifying
how efficient a database is. These classifications are
called normal forms (or NF), and there are algorithms
for converting a given database between them.
Normalization generally involves splitting existing
tables into multiple ones, which must be re-joined or
linked each time a query is issued.
Normal Forms
First Normal Form (1NF)

Second Normal Form (2NF)


Third Normal Form (3NF)
Boyce-Codd Normal Form (BCNF)
Fourth Normal Form (4NF)
Fifth Normal Form (5NF)
Functional
dependency
No transitive
of nonkey
dependency
attributes on
between
the primary
nonkey
attributes
Boyce- key - Atomic
Codd and values only
Higher
All Full
determinants Functional
are candidate dependency
keys - Single of nonkey
multivalued attributes on
dependency the primary
key

IS 257 – Fall 2006


First Normal Form (1NF)
A relation is in first normal form (1NF) if all its
attribute values are atomic.
That is, a 1NF relation cannot have an attribute value
that is:
 a set of values (multi-valued attribute)
 a set of tuples (nested relation)
A relation that is not in 1NF is an unnormalized
relation.
A non-1NF Relation

Two ways to convert a non-1NF relation to a 1NF relation:


1) Splitting Method - Divide the existing relation into two relations: non-
repeating attributes and repeating attributes.
􀃖Make a relation consisting of the primary key of the original relation and the
repeating attributes. Determine a primary key for this new relation.
􀃖Remove the repeating attributes from the original relation.
2) Flattening Method - Create new tuples for the repeating data combined
with the data that does not repeat.
􀃖Introduces redundancy that will be later removed by normalization.
􀃖Determine primary key for this flattened relation.
Converting a non-1NF Relation
to 1NF Using Splitting
Converting a non-1NF Relation
to 1NF Using Flattening
Second Normal Form (2NF)
 A relation is in second normal form (2NF) if it is in 1NF and every
non-primary key (non-prime) attribute is fully functionally
dependent on the primary key.
 Alternative definition from your text: every nonkey column
depends on all candidate keys, not a subset of any candidate
key
 Violations:
 Part of key -> nonkey
Note: By definition, any relation with a single primary key attribute is
always in 2NF.
 If a relation is not in 2NF, we will divide it into separate relations each
in 2NF by insuring that the primary key of each new relation
functionally determines all the attributes in the relation.
Second Normal Form (2NF) Example

fd1 and fd4 are partial functional dependencies.


Normalize to:
 Emp (eno, ename, title, bdate, salary, supereno, dno)
 WorksOn (eno, pno, resp, hours)
 Proj (pno, pname, budget)
Second Normal Form (2NF) Example
Third Normal Form (3NF)
 Third normal form (3NF) is based on the notion of transitive
dependency. A transitive dependency A → C is a FD that can be
inferred from existing FDs A → B and B → C.
 Note that a transitive dependency may involve more than 2 FDs.
 A relation is in third normal form (3NF) if it is in 2NF and there is
no non-primary key (non-prime) attribute that is transitively
dependent on the primary key.
 Alternate definition from your text: A table is in 3NF if it is in 2NF
and each nonkey column depends only on candidate keys, not on
other nonkey columns
 Violations: Nonkey  Nonkey
 Converting a relation to 3NF from 2NF involves the removal of
transitive dependencies. If a transitive dependency exists, we remove
the transitively dependent attributes from the relation and put them
in a new relation along with a copy of the determinant (LHS of FD).
Third Normal Form (3NF) Example

fd2 results in a transitive dependency eno → salary. Remove it.


General Definitions of 2NF and 3NF
We have defined 2NF and 3NF in terms of primary
keys. However, a more general definition considers all
candidate keys (just not the primary key we have
chosen).
General definition of 2NF:
 A relation is in 2NF if it is in 1NF and every non-prime
attribute is fully functionally dependent on any candidate
key.
General definition of 3NF:
 A relation is in 3NF if it is in 2NF and there is no non-prime
attribute that is transitively dependent on any candidate
key.
Note that a prime attribute is an attribute that is in any
key (candidate or primary).
Boyce-Codd Normal Form (BCNF)
 A relation is in Boyce-Codd normal form (BCNF) if and only if
every determinant is a candidate key.
 The difference between 3NF and BCNF is that 3NF allows a FD X →
Y to remain in the relation if X is a superkey or Y is a prime
attribute. BCNF only allows this FD if X is a superkey.
 Thus, BCNF is more restrictive than 3NF. However, in practice most
relations in 3NF are also in BCNF.
Boyce-Codd Normal Form (BCNF)
Consider the WorksOn relation where we have the
added constraint that given the hours worked, we
know exactly the employee who performed the work.
(i.e. each employee is FD from the hours that they
work on projects). Then:

Note that we lose the FD eno,pno → resp, hours.


Multi-Valued Dependencies
 A multi-valued dependency (MVD) occurs when two independent,
multi-valued attributes are present in the schema.
 A MVD occurs when two independent 1:N relationships are in the
relational schema.
 When these multi-valued attributes are flattened into a 1NF
relation, we must have a tuple for every combination of the values
in the two attributes.
 It may seem strange why we would want to do this as it obviously
increases the number of tuples and redundancy.
 The reason is that since the two attributes are independent it does
not make sense to store some combinations and not the others
because all combinations are equally valid. By leaving out some
combination, we are unintentionally favoring one combination over
the other which should not be the case.
Employee may:
Multi-Valued Dependencies Example
- work on many projects
- be in many departments
Multi-Valued Dependencies (MVDs)
A multi-valued dependency (MVD) is a dependency
between attributes A, B, C in a relation such that for
each value of A there is a set of values B and a set of
values C where the set of values B and C are
independent of each other.
A MVD is denoted as A → → B and A → → C or
abbreviated as A → → B | C.
Fourth Normal Form (4NF)
 Fourth normal form (4NF) is based on the idea of multi-valued
dependencies.
 A relation is in fourth normal form (4NF) if it is in BCNF and
contains no non-trivial multi-valued dependencies.
 Formal definition: A relation schema R is in 4NF with respect to a
set of dependencies F if, for every nontrivial multi-valued
dependency X → → Y, X is a superkey of R.
 If X → → Y is a 4NF violation for relation R, we can decompose R
using the same technique as for BCNF:
 XY is one of the decomposed relations.
 All but Y – X is the other.
Fourth Normal Form (4NF) Example
Lossless-join Dependency
The lossless-join property refers to the fact that
whenever we decompose relations using
normalization we can rejoin the relations to produce
the original relation.
A lossless-join dependency is a property of
decomposition which ensures that no spurious tuples
are generated when relations are natural joined.
There are cases where it is necessary to decompose a
relation into more than two relations to guarantee a
lossless-join.
Fifth Normal Form (5NF)
Fifth normal form (5NF) is based on join
dependencies.
A relation is in fifth normal form (5NF) if nad only if
every nontrivial join dependency is implied by the
superkeys of R.
A join dependency (JD) denoted by JD(R1, R2, …, Rn)
on relational schema R specifies a constraint on the
states r of R. The constraint states that every legal state
r of R is equal to the join of its projections on R1, R2,
…, Rn. That is for every such r we have:
 ΠR1(r) ∗ ΠR2(r) ∗ … ∗ ΠRn(r) = r
Fifth Normal Form (5NF) Example
Consider a relation Supply (sname, partName, projName).
Add the additional constraint that:
If project j requires part p
and supplier s supplies part p
and supplier s supplies at least one item to project j Then
supplier s also supplies part p to project j
Fifth Normal Form (5NF) Example

Let R be in BCNF and let R have no composite keys. Then R is in 5NF


Note: That only joining all three relations together will get you back to the original
relation. Joining any two will create spurious tuples!
Normalizing to death
Normalization splits database information across
multiple tables.
To retrieve complete information from a normalized
database, the JOIN operation must be used.
JOIN tends to be expensive in terms of processing
time, and very large joins are very expensive.

IS 257 – Fall 2006


THANK YOU

You might also like