6 Normalization Part 1
6 Normalization Part 1
Management Systems
Normalization
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 1 1
Overview Today we’ll discuss
Database Normalization
Brief History/Overview
○ Conclusion
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 6 6
• Suppose we started with Large Schema
Inst_dept(Id, name, salary, dept_name, building, budget)
Eliminate redundancy.
Insertion Anomaly
If the primary key is EmpId + Course, to add a new employee, the employee must
first be enrolled in a course.
If an employee is not enrolled in a course, then the COURSE column that is part of
the composite primary key will be null, and null key values are not allowed.
Deletion Anomaly.
Deleting data for Employee #425 (Bill) causes us to lose data about
Algebra and the course fee for Algebra because Bill is the only employee
who has enrolled in Algebra.
Modification Anomaly.
If the fee for Calculus is increased, the data must be updated for more
than one row.
Bindu K. R. Dept. of CSE., Amrita School of Engineering, Coimbatore September 2020 18
Brief History/Overview
Database Normalization was first proposed by Edgar F.
Codd.
Codd defined the first three Normal Forms.
In order to do normalization we must know what the
requirements are for each of the three Normal Forms .
One of the key requirements to remember is that Normal
Forms are progressive.
That is, in order to have 3rd NF we must have 2nd NF and in
order to have 2nd NF we must have 1st NF.
• Goal: to generate set of relations schemas that allow us to store the data with out redundancy and to
retrieve the data easily.
• To check the normal form we need additional information, such as functional dependency. (Conditions)
In 1 NF
dept_name budget
In X→Y, X functionally determines Y. The left-hand side attributes
determine the values of attributes on the right-hand side.
Bindu K. R. Dept. of CSE., Amrita School of Engineering, Coimbatore September 2020 32
Functional Dependencies
1. If one set of attributes in a table determines another
set of attributes in the table, then the second set of
attributes is said to be functionally dependent on the
first set of attributes.
{ISBN} {Price}
{PubId} {PubName}
Example 3
{PubName, PubPhone} {PubID}
Table Scheme: {AuID, AuName, AuPhone}
Functional Dependencies:
{AuId} {AuPhone}
{AuId} {AuName}
In a relation A B means, for any two tuples t1 and t2 if t1[A]=t2[A] then t1[B]= t2[B].
Example.
A A
3. {City} {CityPopulation}
6. {studio} {studio_city}
studio_city is not a part of a key
studio_city functionally depends on studio which is a proper subset of the key
Bindu K. R. Dept. of CSE., Amrita School of Engineering, Coimbatore September 2020 39
2NF - Decomposition
1. If a data item is fully functionally dependent on only a part of the
primary key, move that data item and that part of the primary key to
a new table.
2. If there are other data items which are functionally dependent on the
same part of the key, place them also in the new table.
3. Make the partial primary key copied from the original table as the
primary key for the new table. Place all items that appear in the
repeating group in a new table
Example 1 (Convert to 2NF)
Old Schema {Title, PubId, AuId, Price, AuAddress}
New Schema {Title, PubId, AuId, Price}
New Schema {AuId, AuAddress}
Bindu K. R. Dept. of CSE., Amrita School of Engineering, Coimbatore September 2020 40
2NF - Decomposition
Example 2 (Convert to 2NF)
Old Schema {Studio, Movie, Budget, StudioCity}
New Schema {Movie, Studio, Budget}
New Schema {Studio, StudioCity}
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 42 42
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 43 43
A table is in 2NF, only if a relation is in 1NF and meet all the rules, and every non-key attribute is fully
dependent on primary key.
The Second Normal Form eliminates partial dependencies on primary keys.
Let us see an example −
In the given table, we have partial dependency; let us see
how −
• The prime key attributes are StudentID and
ProjectID.
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 44 44
• COURSE_FEE cannot alone decide the value of
COURSE_NO or STUD_NO;
Hence,
COURSE_FEE would be a non-prime attribute, as it
does not belong to the one only candidate key
{STUD_NO, COURSE_NO} ;
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 45 45
This table has a composite primary key [Customer ID, Store ID]. The non-key attribute is [Purchase
Location].
In this case, [Purchase Location] only depends on [Store ID], which is only part of the primary key.
Therefore, this table does not satisfy second normal form.
To bring this table to second normal form, we break the table into two tables, and now we have the
following:
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 46 46
3 NF
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 47 47
What do you understand from the
diagram below?
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 48 48
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 49 49
Is there any partial FD?
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 50 50
Which normal form is carried
out?
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 51 51
Third Normal Form
• 2NF and no transitive dependencies
Full FDs
StudentID StudentName
(StudentID, ProgramId, StudentName) StudentID ProgramId
StudentID ProgramName
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 55 55
• A table design is said to be in 3NF if both the following conditions hold:
• Table must be in 2NF
• Transitive functional dependency of non-prime attribute on any super key should be removed.
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 56 56
Third Normal Form (3NF)
FD set:
A relation is in third normal form, if there is no {STUD_NO -> STUD_NAME,
transitive dependency for non-prime attributes as STUD_NO -> STUD_STATE,
well as it is in second normal form. STUD_STATE -> STUD_COUNTRY,
STUD_NO -> STUD_AGE}
Candidate Key:
{STUD_NO}
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 57 57
The following dependencies exist:
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 58 58
In the table able, [Book ID] determines [Genre ID], and [Genre ID] determines [Genre Type].
Therefore, [Book ID] determines [Genre Type] via [Genre ID] and we have transitive functional
dependency, and this structure does not satisfy third normal form.
To bring this table to third normal form, we split the table into two as follows:
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 59 59
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 60 60
You Try…
Is it in 3NF?
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 61 61
Cust_id zip
You Try…
zip Street, City, State
Not in 3NF
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 62 62
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 63 63
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 64 64
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 65 65
Bindu
Bindu
K. R.
K. R. Dept.Dept.
of CSE.,
of CSE.,
Amrita
Amrita
School
School
of Engineering,
of Engineering,
Coimbatore
Coimbatore
September
September
2020
2020 66 66
Conclusion
We have seen how
Database Normalization can
Decrease redundancy
Reduce anomalies
by implementing three of different levels of normalization
called Normal Forms.
The first three Normal Forms are usually sufficient for most small to
medium
Bindu size
K. R. Dept. applications.
of CSE., Amrita School of Engineering, Coimbatore September 2020 67
References
Hillyer Mike, MySQL AB. An Introduction to Database
Normalization,
http://dev.mysql.com/tech-resources/articles/intro-to-normalizatio
n.html
, accessed October 17, 2006.