3. NORMALIZATION OF DATABASE
Database Normalization is a technique of organizing the data in the
database. Normalization is a systematic approach of decomposing
tables to eliminate data redundancy and undesirable characteristics like
Insertion, Update and Deletion Anomalies .
Normalization is used for mainly two purpose
Eliminating redundant(useless) data.
The problem usually happens when an existing system uses unstructured file, e.g. in M
8/8/2017 3
4. PROBLEM WITHOUT NORMALIZATION
Without Normalization, it becomes difficult to handle and update
the database, without facing data loss. Insertion, Updation and
Deletion Anomalies are very frequent if Database is not Normalized.
S_id S_Name S_Address Subject_opted
401 Adam Noida Bio
402 Alex Panipat Maths
403 Stuart Jammu Maths
404 Adam Noida Physics
8/8/2017 4
5. PROBLEM WITHOUT NORMALIZATION
Updation Anomaly
Insertion Anomaly
Deletion Anomaly
S_id S_Name S_Address Subject_opted
401 Adam Noida Bio
402 Alex Panipat Maths
403 Stuart Jammu Maths
404 Adam Noida Physics
8/8/2017 5
6. NORMALIZATION RULE
Normalization rule are divided into following normal
form :
First Normal Form
Second Normal Form
Third Normal Form
8/8/2017 6
7. FIRST NORMAL FORM(1NF)
THE OFFICIAL QUALIFICATIONS FOR 1NF ARE:
1. Each Attribute Name Must Be Unique.
2. Each Attribute Value Must Be Single.
3. Each Row Must Be Unique.
4. There Is No Repeating Groups.
78/8/2017
8. FIRST NORMAL FORM(1NF)
8
Example of a table not in 1NF :
It violates the 1NF.
Student Age Subject
Adam 15 Biology, Maths
Alex 14 Maths
Stuart 17 Maths
8/8/2017
9. FIRST NORMAL FORM (1NF)
9
Now it is in 1NF.
However, it might still violate 2NF and so on.
Student Age Subject
Adam 15 Biology
Adam 15 Maths
Alex 14 Maths
Stuart 17 Maths
8/8/2017
10. FUNCTIONAL DEPENDENCIES
10
We say an attribute, B, has a functional dependency on another attribute, A, if for any two
records, which have
the same value for A, then the values for B in these two records must be the same. We
illustrate this as:
A B (read as: A determines B or B depends on A)
employee name email address
employee name project email address
Sok San POS Mart Sys soksan@yahoo.com
Sao Ry Univ Mgt Sys sao@yahoo.com
Sok San Web Redesign soksan@yahoo.com
Chan Sokna POS Mart Sys chan@gmail.com
Sao Ry DB Design sao@yahoo.com
8/8/2017
11. FUNCTIONAL DEPENDENCIES
11
EmpNum EmpEmail EmpFname EmpLname
123 jdoe@abc.com John Doe
456 psmith@abc.com Peter Smith
555 alee1@abc.com Alan Lee
633 pdoe@abc.com Peter Doe
787 alee2@abc.com Alan Lee
If EmpNum is the PK then the FDs:
EmpNum EmpEmail, EmpFname, EmpLname
must exist.
8/8/2017
14. SECOND NORMAL FORM(2NF)
THE OFFICIAL QUALIFICATIONS FOR 2NF
ARE:
1. A TABLE IS ALREADY IN 1NF.
2. ALL NONKEY ATTRIBUTES ARE FULLY DEPENDENT ON THE PRIMARY KEY.
ALL PARTIAL DEPENDENCIES ARE REMOVED TO PLACE IN ANOTHER TABLE.
128/8/2017
15. CourseID SemesterID Num Student Course Name
IT101 201301 25 Database
IT101 201302 25 Database
IT102 201301 30 Web Prog
IT102 201302 35 Web Prog
IT103 201401 20 Networking
Example of a table not in 2NF:
Primary Key
The Course Name depends on only CourseID, a part of the primary key
not the whole primary {CourseID, SemesterID}.It’s called partial
dependency.
15
SECOND NORMAL FORM(2NF)
8/8/2017
16. CourseID Course Name
IT101 Database
IT101 Database
IT102 Web Prog
IT102 Web Prog
IT103 Networking
SemesterDone? Oh no, it is still
not in 1NF yet.
Remove the repeating
groups too.
Finally, connect the
relationship.
CourseID Course Name
IT101 Database
IT102 Web Prog
IT103 Networking
CourseID SemesterID Num Student
IT101 201301 25
IT101 201302 25
IT102 201301 30
IT102 201302 35
IT103 201401 20
16
SECOND NORMAL FORM(2NF)
8/8/2017
17. THIRD NORMAL FORM (3NF)
THE OFFICIAL QUALIFICATIONS FOR 3NF ARE:
1. A TABLE IS ALREADY IN 2NF.
2. NONPRIMARY KEY ATTRIBUTES DO NOT DEPEND ON OTHER NONPRIMARY
KEY ATTRIBUTES
178/8/2017
18. StudyID Course Name Teacher Name Teacher Tel
1 Database Sok Piseth 012 123 456
2 Database Sao Kanha 0977 322 111
3 Web Prog Chan Veasna 012 412 333
4 Web Prog Chan Veasna 012 412 333
5 Networking Pou Sambath 077 545 221
Example of a Table not in 3NF:
Primary Key
18
THIRD NORMAL FORM (3NF)
8/8/2017
19. Teacher Name Teacher Tel
Sok Piseth 012 123 456
Sao Kanha 0977 322 111
Chan Veasna 012 412 333
Chan Veasna 012 412 333
Pou Sambath 077 545 221
Done?
Oh no, it is still not in 1NF yet.
Remove Repeating row.
Teacher Name Teacher Tel
Sok Piseth 012 123 456
Sao Kanha 0977 322 111
Chan Veasna 012 412 333
Pou Sambath 077 545 221
Note about primary key:
- In theory, you can choose
Teacher Name to be a primary key.
- But in practice, you should add
Teacher ID as the primary key.
ID Teacher Name Teacher Tel
T1 Sok Piseth 012 123 456
T2 Sao Kanha 0977 322
111
T3 Chan Veasna 012 412 333
T4 Pou Sambath 077 545 221
StudyID Course Name T.ID
1 Database T1
2 Database T2
3 Web Prog T3
4 Web Prog T3
5 Networking T4
198/8/2017
20. JOIN
Join Is A Special Form Of Cross Product
Of Two Tables.
In Cartesian Product We Join A Tuple Of
One Table With The Tuples Of The
Second Table. But In Join There Is A
Special Requirement Of Relationship
Between Tuples.
8/8/2017 20
22. INNER JOIN
AN INNER JOIN IS THE MOST COMMON JOIN OPERATION USED IN
APPLICATIONS AND CAN BE REGARDED AS THE DEFAULT JOIN-
TYPE.
INNER JOIN CREATES A NEW RESULT TABLE BY COMBINING
COLUMN VALUES OF TWO TABLES (A AND B) BASED UPON THE
JOIN-PREDICATE.
8/8/2017 22
23. Θ-JOIN
CONSIDER TABLES CAR AND BOAT WHICH LIST MODELS OF CARS
AND BOATS AND THEIR RESPECTIVE PRICES.
SUPPOSE A CUSTOMER WANTS TO BUY A CAR AND A BOAT, BUT
SHE DOES NOT WANT TO SPEND MORE MONEY FOR THE BOAT
THAN FOR THE CAR.
8/8/2017 23
24. EQUI JOIN
AN EQUI-JOIN, ALSO KNOWN AS AN EQUIJOIN, IS A SPECIFIC TYPE
OF COMPARATOR-BASED JOIN, OR THETA JOIN, THAT USES
ONLY EQUALITY COMPARISONS IN THE JOIN-PREDICATE. USING
OTHER COMPARISON OPERATORS (SUCH AS <) DISQUALIFIES A
JOIN AS AN EQUI-JOIN.
8/8/2017 24
26. NATURAL JOIN
NATURAL JOIN ( ) IS A BINARY OPERATOR THAT IS WRITTEN AS
(R S) WHERE R AND S ARE RELATIONS.
IN PARTICULAR, NATURAL JOIN ALLOWS THE COMBINATION OF
RELATIONS THAT ARE ASSOCIATED BY A FOREIGN KEY.
8/8/2017 26
27. OUTER JOIN
An Outer Join Does Not Require Each Record In The Two Joined
Tables To Have A Matching Record. The Joined Table Retains Each
Record—even If No Other Matching Record Exists.
8/8/2017 27
28. LEFT OUTER JOIN
The Result Of A Left Outer Join (Or Simply Left Join) For Table A And B Always
Contains All Records Of The "Left" Table (A), Even If The Join-condition Does
Not Find Any Matching Record In The "Right" Table (B).
Employee
Dept
Employee =X Dept
8/8/2017 28
30. RIGHT OUTER JOIN
A RIGHT OUTER JOIN (OR RIGHT JOIN) CLOSELY RESEMBLES A LEFT OUTER JOIN,
EXCEPT WITH THE TREATMENT OF THE TABLES REVERSED
Employee X= Dept
Employee
Dept
8/8/2017 30
32. FULL OUTER JOIN
Conceptually, A Full Outer Join Combines The Effect Of Applying Both Left And
Right Outer Joins.
Employee =X= Dept
Employee
Dept
8/8/2017 32