4 - Normalization
4 - Normalization
Definitions
• A process of analyzing a relation to ensure that it is well formed
◦ Update Anomaly - exists when one or more instances of duplicated data is updated,
but not all
◦ Deletion Anomaly - exists when certain attributes are lost because of the deletion of
other attributes
Insertion Anomaly - occurs when certain attributes cannot be inserted into
the database without the presence of other attributes
Student
Stud_ID Stud_Name No_Subject College Build_No Room_No
101 Snowhite 4 COC B2 R101 Update Anomaly
Update Anomaly - exists when one or more instances of duplicated data is updated,
but not all
Deletion Anomaly - exists when certain attributes are lost because of the deletion of
other attributes
Insertion Anomaly
customerId customerName carId year make model
Hanae
1 Osaka D01 Accounting Valdez
Yoshimori
Donald
6 Mumbai D01 Accounting Valdez
McElhenny
EmpID EmpName Address DeptID DeptName DeptMgr
Hanae
1 Osaka D01 Accounting Valdez
Yoshimori
2 Atsuko Imai Tokyo D02 Operations Deverala
Chigusa
3 Nagoya D03 Services Talavera
Sazaki
4 Reiko Kawai Kyoto D04 Training Antonio
Functional dependency
• A constraint between two attributes in which the value of one attribute is
determined by the value of another attribute
(Constraint – certain properties that data must comply with)
Examples:
ISBN -> Title,FirstAuthorName, Publisher
ISBN 978-981-4586-96-2 – Modern Database Mgnt, 11th Ed, Hoffer , Prescott,
Topi – Pearson Educ.
You can also describe this as a relationship where knowing the
value of one attribute (or a set of attributes) is enough to tell you
the value of another attribute (or set of attributes) in the same
table.
Examples:
SSS No. -> Employee’s Name
Bank Account No. -> Customer Name
Functional dependency
Illustration: Student
Stud_ID StudName Grade College Code
determinant dependent
1 a 78 CCIS C1
FD attribute1 attribute2 2 b 80 COE C1
3 a 78 CCIS C2
FD x y x y
4 b 60 COE C2
1 1
y is functionally dependent on x 5 c 80 COC C2
2 1
6 d 80 MT C2
x determines y 3 2
4 6 Stud_ID StudName
Not FD 2 9
StudName Stud_ID
FD 3 2
Stud_ID Grade
FD x à y
reference having same determinants If t1x == t2x
College Code
Then t1y == t2y
Student
Stud_ID StudName Grade College Code
1 a 78 CCIS C1
2 b 80 COE C1
3 a 78 CCIS C2
4 b 80 COE C2 FD x à y
5 c 60 COC C2 If t1x == t2x
Then t1y == t2y
6 d 80 MT C2
StudName Grade
Grade College
StudName College
1750 Kuala
UA 36 3-Sep-16 1410 Manila 200
Lumpur
0455 Kuala
AA 704 31-Oct-16 0120 Manila 150
Lumpur
1750 Kuala
UA 36 4-Sep-16 1410 Manila 190
Lumpur
0435 Kuala
BA 9 31-Oct-16 0100 Manila 100
Lumpur
Types of Functional Dependency Student
A trivial functional dependency is a database dependency that occurs when you describe
a functional dependency of an attribute or of a collection of attributes that includes the original
attribute.
Stud_ID StudName Grade College Code
Trivial xày Student_ID à Student_ID 1 a 78 CCIS C1
If y C x
xàx Student_ID, StudName à StudName 2 b 80 COE C1
3 a 78 CCIS C2
Student_ID , StudName à Student_ID
Functional dependency which also known as a nontrivial dependency occurs when 4 b 60 COE C2
A->B holds true where B is not a subset of A. In a relationship, if attribute B is not a
subset of attribute A, then it is considered as a non-trivial dependency. 5 c 80 COC C2
xày 6 d 80 MT C2
Non-Trivial Student_ID à StudName
If x ⊄ y
xày
SemiTrivial Student_ID , StudName à StudName, Grade Employee
If x ⊄ y
Ename Project Dept
Joe DBMS Accounting
Multivalued (x à ày, x à à z) (Ename à àProjecty, Ename à à Dept) Joe Java Payroll
Transivity
if(x à y & y à z)
then x à z
ABC à D
Flight No. of
Date From To
Number Passengers
1750 Kuala
UA 36 3-Sep-16 1410 Manila 200
Lumpur
0455 Kuala
AA 704 31-Oct-16 0120 Manila 150
Lumpur
1750 Kuala
UA 36 4-Sep-16 1410 Manila 190
Lumpur
0435 Kuala
BA 9 31-Oct-16 0100 Manila 100
Lumpur
Transitive dependency – a functional dependency between the
primary key and one or more nonkey attributes that are
dependent on the primary key via another nonkey attribute
A B C
Steps in Normalization
Normalization can be accomplished in stages, each of which
corresponds to a normal form
Customer ID : 22
Customer Name : Dan’s Furniture
Customer Address : Fullerton, California
Customer ID : 65
Customer Name : Furniture Barn
Customer Address : Fort Collins, Colorado
Customer ID : 65
Customer Name : Furniture Barn
Customer Address : Fort Collins, Colorado
P Q R S T DECOMPOSE relation R
R1(P, R)
partial FD
R2(P, Q, T)
PR is the candidate key
R3(R, S)
example 3
1 3 5 3 Nayre 1 Bea
Sid Sname Tid Tname Grade 2 2 4 2 Dastas 2 Angel
3 1 6 1 Cruz 3 Ivana
partial FD partial FD
Order Order Cust Customer Customer Prod Product Product Unit Ordered
ID Date ID Name Address ID Description Finish Price Qty
Product Product
Product ID Unit Price
Description Finish
Ordered
Order ID Product ID
Quantity
Third Normal Form (3NF)
vA relation should be in 2NF
vAny transitive dependencies have been removed
Transitive dependency – a functional dependency between the primary key and one or more nonkey attributes that
are dependent on the primary key via another nonkey attribute
This means if we have a primary key A and a non-key domain B and C where C is more dependent on B than A and B
is directly dependent on A, then C can be considered transitively dependant on A.
DECOMPOSE relation R
A B C D E
R1(A, C)
partial FD partial FD
R2(A, B)
R3(B, E)
AC is the candidate key
R4(C, D)
example 2
Product Product
Product ID Unit Price
Description Finish
Ordered
Order ID Product ID
Quantity
Third Normal Form
2NF PLUS No transitive dependencies
Product Ordered
Order ID
ID Quantity
Dependency Diagram Full Dependency
Transitive Dependencies
Order Order Cust Customer Customer Prod Product Product Unit Ordered
ID Date ID Name Address ID Description Finish Price Qty
ORDER
Ex.
With redundant data, when we want to change the value of one columns of a particular Dentist, for example the dentistName,
we must update all the Dentist records that assigned to the particular patient otherwise the database will become inconsistent.
We also need to modify the appointment schedules because different Dentist has different schedules.
(b) Describe and illustrate the process of normalizing the table shown in Figure 1 to 3NF. State any assumptions you make
about the data shown in this table.
Assumptions made include that a patient is registered at only one surgery and he/she may have more than one appointment on
a given day. All the schedules have been fixed for the whole days and week.
In the 1NF we remove all the repeating groups (appointment), assigning new column (apptDate and apptTime) and assigned
primary keys (candidate keys). Then we figure out the functional dependencies (FDs). By using dependency diagram we
represent the table as shown below. (NF – stand for Normal Form)
Note: How to find the FDs is subjective!!! However, the rule is, it must reflect the real word situation.
staffNo apptDate apptTime dentistName patientNo patientName surgeryNo
FD1 is already in 2NF. In this case, we can see that FD2 (just depend on staffNo) and FD4 (just depend on staffNo and apptDate)
violate the 2NF. These two NFs are partially dependent on the candidate keys not the whole keys. FD2 can stand on its own by
depending on the staffNo and meanwhile FD4 also can stand on its own by depending on the staffNo.
The FD3 violates the 3NF showing the transitive dependency where surgeryNo and patientName depend on patientNo while
patientNo depend on the staffNo that is the non-key is depending on another non-key.
staffNo apptDate apptTime dentistName patientNo patientName surgeryNo
staffNo dentistName
The 2NF, it is already in 1NF and there is no partial dependency. So we need to remove the FD2 and FD4 by splitting into
new tables and at the same time creating foreign keys.
staffNo apptDate apptTime dentistName patientNo patientName surgeryNo
FK
FK
staffNo apptDate surgeryNo
staffNo dentistName
patientNo patientName
Finally in 3NF we must remove the transitive dependency. In this case we remove the FD3 by splitting into a new table.
The transitive dependency left is the patientName that depend on the patientNo, so we split this into new table while
creating a foreign key.
staffNo dentistName
Dentist(staffNo, dentistName)
FK
staffNo apptDate surgeryNo
patientNo patientName
Patient(patientNo, patientName)
FK
staffNo apptDate apptTime patientNo
https://www.javaguicodexample.com/normalizationexercisean
swer.pdf