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

Normalization 01

Uploaded by

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

Normalization 01

Uploaded by

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

Normalization

1
Normalization
 The biggest problem needed to be solved in database
is data redundancy.
 Why data redundancy is the problem? Because it
 Insert Anomaly
causes:
 Update Anomaly
 Delete Anomaly

Teacher Subject Teacher Degree Tel

Sok San Database Master's 012666777

Van Sokhen Database Bachelor's 017678678

Sok San E-Commerce Master's 012666777

2
Normalization (Cont.)
 Normalization is the process of removing redundant
data from your tables to improve storage efficiency,
data integrity, and scalability.
 Normalization generally involves splitting existing
tables into multiple ones, which must be re-joined or
linked each time a query is issued.
 Why normalization?
 The relation derived from the user view or data store will most
likely be unnormalized.
 The problem usually happens when an existing system uses
unstructured file, e.g. in MS Excel.

3
Steps of Normalization
 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)

In practice, 1NF, 2NF, and 3NF are enough for database.

4
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.
 Additional:
 Choose a primary key.

 Reminder:
A primary key is unique, not null, unchanged. A
primary key can be either an attribute or combined
attributes.
5
First Normal Form (1NF) (Cont.)
 Example of a table not in
1NF :
Group Topic Student Score
Group A Intro MongoDB Sok San 18 marks
Sao Ry 17 marks
Group B Intro MySQL Chan Tina 19 marks
Tith Sophea 16 marks

It violates the 1NF because:


 Attribute values are not
single.
 Repeating groups exists.

6
For example ;
Let's say you have a table called "Employee" with columns "Employee ID," "First
Name," "Last Name," and "Phone Numbers." The "Phone Numbers" column
stores multiple phone numbers separated by commas. To normalize this table
into 1NF, you would create a separate table for phone numbers linked to the
employee ID. So, each phone number would be in a separate row in the new
table, linked to the employee through their ID.

Let's consider a table called "Orders" which tracks orders placed by customers.
Here's how the table looks before normalization:
First Normal Form (1NF) (Cont.)
 After
eliminating:
Group Topic Family Name Given Name Score
A Intro MongoDB Sok San 18
A Intro MongoDB Sao Ry 17
B Intro MySQL Chan Tina 19
B Intro MySQL Tith Sophea 16

 Now it is in 1NF.
However, it might still violate 2NF and so on.

9
Functional Dependencies
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 project email address
Sok San POS Mart Sys [email protected]
Sao Ry Univ Mgt Sys [email protected]
Sok San Web Redesign [email protected]
Chan Sokna POS Mart Sys [email protected]
Sao Ry DB Design [email protected]

employee name  email address


Functional Dependencies (cont.)
EmpNum EmpEmail EmpFname EmpLname
123 [email protected] John Doe
456 [email protected] Peter Smith
555 [email protected] Alan Lee
633 [email protected] Peter Doe
787 [email protected] Alan Lee

If EmpNum is the PK then the FDs:


EmpNum  EmpEmail, EmpFname,
EmpLname
must exist.
Functional Dependencies (cont.)
Three ways might see function dependency
1. EmpNum  EmpEmail, EmpFname, EmpLnam

2. EmpEmail
EmpNum EmpFname
EmpLname

3. EmpNum EmpEmail EmpFname EmpLname


Determinant
Functional Dependency

EmpNum  EmpEmail

Attribute on the left hand side is known as the


determinant
• EmpNum is a determinant of EmpEmail
Second Normal Form (2NF)
Rule for Second Normal Form (2NF):
A relation is in 2NF if it is in 1NF and every non-prime attribute
(attributes not part of any candidate key) is fully functionally
dependent on the whole of every candidate key.
In simpler terms, a table is in 2NF if it meets the following conditions:
It is already in 1NF (i.e., there are no repeating groups or composite
values in any attribute).
Every non-prime attribute is fully functionally dependent on the entire
candidate key, meaning that every non-key attribute is dependent on
the entire primary key, not just a part of it.
Example of a table not in 2NF:

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

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.
Solution:
Remove CourseID and Course Name together to create a new table.
CourseID Course Name C ourseI D SemesterID Num Student
IT101 Database IT101 201301 25
IT101 Database IT101 201302 25
IT102 Web Prog IT102 201301 30
IT102 Web Prog IT102 201302 35
IT103 Networking IT103 201401 20

Done? Oh no, it is still


not in 1NF yet.
Remove the repeating
groups too.
Finally, connect the CourseID Course Name
relationship. IT101 D atabas
IT102 e
Web Prog
IT103 Networking
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
(i.e. no transitive dependencies)
All transitive dependencies are removed to place
in another table.
Example of a Table not in 3NF:

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

Primary Key
The Teacher Tel is a nonkey attribute, and
the Teacher Name is also a nonkey atttribute.
But Teacher Tel depends on Teacher Name.
It is called transitive dependency.

Solution:
Remove Teacher Name and Teacher Tel together
to create a new table.
Done?
Teacher Name Teacher Tel
Oh no, it is still not in 1NF yet.
Sok Piseth 012 123 456 Remove Repeating row.
Sao Kanha 0977 322 111
StudyI D C ourse N ame T .I D
Chan Veasna 012 412 333
1 Database T1
Chan Veasna 012 412 333
2 Database T2
Pou Sambath 077 545 221
3 Web Prog T3
Teacher Name Teacher Tel 4 Web Prog T3
Sok Piseth 012 123 5 Networking T4
Sao Kanha 456
0977 322
Chan Veasna 111
012 412
Pou 333
077 545
Sambath 221
ID Teacher Name Teacher Tel
Note about T1 Sok 012 123
primary key: Piseth Sao
T2 456
0977 322
Kanha
T3 Chan 111
012 412
-In theory, you
can choose Veasna
T4 Pou 333
077 545
Boyce Codd Normal Form (BCNF) – 3.5NF
The official qualifications for BCNF are:
1. A table is already in 3NF.
2. All determinants must be superkeys.
All determinants that are not superkeys are removed to place
in another table.
Boyce Codd Normal Form (BCNF) (Cont.)
 Example of a table not in
BCNF:
Student Course Teacher
Sok DB John
Sao DB William
Chan E-Commerce Todd
Sok E-Commerce Todd
Chan DB William

 Key: {Student, Course}


 Functional Dependency:
 {Student, Course}
 Teacher  Course
Teacher
 Problem: Teacher is not a superkey but determines Course.
Solution: Decouple a table
Student Course
contains Teacher and Course
Sok DB from from original table (Student,
Sa DB Course). Finally, connect the new
o and old table to third table
C ha E-Commerce contains Course.
n
Sok E-Commerce
C ha DB Course
n DB
E-Commerce
Course Teacher
DB Joh
n
DB W illia
m
E-Commerce Tod
d
Forth Normal Form (4NF)
The official qualifications for 4NF are:
1. A table is already in BCNF.
2. A table contains no multi-valued dependencies.

 Multi-valued dependency: MVDs occur when


two or more independent multi valued facts about
the same attribute occur within the same table.
A  B (B multi-valued depends on A)
Forth Normal Form (4NF) (Cont.)
 Example of a table not in
4NF:
Student Major Hobby
Sok IT Football
Sok IT Volleyball
Sao IT Football
Sao Med Football
Chan IT NULL
Puth NULL Football
Tith NULL NULL

 Key: {Student, Major, Hobby}


 MVD: Student  Major, Hobby
Solution: Decouple to each Student M ajo
table contains MVD. Finally, Sok r
IT
connect each to a third table
contains Student. Sa IT
o
Sa Me
Student o ha
C d
IT
Sok n
Put N ULL
Sao h
Tit N ULL
Chan h
Puth Student Hobby
Tith Sok Football
Sok Volleyball
Sao Football
Chan NULL
Puth Football
Tith NULL
Fifth Normal Form (5NF)
The official qualifications for 5NF are:
1. A table is already in 4NF.
2. The attributes of multi-valued dependencies are
related.
Fifth Normal Form (5NF) (Cont.)
 Example of a table not in
5NF:
Seller Company Product
Sok MIAF Trading Zenya
Sao Coca-Cola Corp Coke
Sao Coca-Cola Corp Fanta
Sao Coca-Cola Corp Sprite
Chan Angkor Brewery Angkor Beer
Chan Cambodia Brewery Cambodia Beer

 Key: {Seller, Company, Product}


 MVD: Seller  Company, Product
 Product is related to Company.
C ompany
Seller C ompany
Seller 1
M
Sok MIAF Trading 1 MIAF Trading
Sok Coca-Cola Corp
Sa Coca-Cola Corp
Sa o Angkor Brewery
C ha Angkor Brewery
o
C ha n Cambodia
C ha Cambodia
n 1 Brewery
1
n Brewery

M
M
1 C ompany Product
Seller Product
MIAF Trading Z eny
Sok a ok
Zenya M Coca-Cola Corp C
Sao e
Product Coca-Cola Corp Fant
C oke
Sao
Zeny Coca-Cola Corp a
Sprit
Fanta
Sao a ok
C e
Sprite Angkor Brewery Angkor Beer
C ha Angkor Beer e
Fant C ambodi C ambodi
n
C ha C ambodi a a a Beer
Sprit
n a Beer Brewery M
e
Angkor Beer 1
Cambodia
Beer
SALES RECORD
1TH NORMAL FORM
2TH NORMAL FORM
3TH NORMAL FORM
4TH NORMAL FORM
4TH NORMAL FORM

You might also like