chp5 Normalization-1
chp5 Normalization-1
- Objectives:
▪ The purpose of normalization.
▪ The problems associated with redundant data.
▪ The identification of various types of update anomalies such as insertion,
deletion, and modification anomalies.
▪ How to recognize the appropriateness or quality of the design of relations.
▪ The concept of functional dependency, the main tool for measuring the
appropriateness of attribute groupings in relations.
▪ How functional dependencies can be used to group attributes into relations
that are in a known normal form.
▪ How to define normal forms for relations. How to undertake the process of
normalization.
▪ How to identify the most commonly used normal forms, namely first (1NF),
second (2NF), and third (3NF) normal forms, and Boyce–Codd normal form
(BCNF).
NORMALIZATION
▪ A technique for producing a set of relations with desirable properties, given the
data requirements of an enterprise. Developed by E.F. Codd (1972).
▪ Often performed as a series of tests on a relation to determine whether it
satisfies or violates the requirements of a given normal form.
▪ Four most commonly used normal forms are first (1NF), second (2NF), third (3NF)
and Boyce-Codd (BCNF) normal forms.
▪ Based on functional dependencies among the attributes of a relation.
▪ A relation can be normalized to a specific form to prevent the possible
occurrence of update anomalies.
▪ Data normalization is the process of structuring data into a form that is …….
- easily accessible and maintainable
- eliminates "anomalies"
which would cause problems during use
The Normalization
▪ Normalization is the process of organizing data in a database.
- redundancy and
- inconsistent dependency.
Relational Database
• The relational database overcomes the limitations of the file-
oriented approach:
• Update anomalies
• Insert anomalies
• Delete anomalies
UNF to 1NF
• Nominate an attribute or group of attributes to act as the key for the
unnormalized table.
• Identify the repeating group(s) in the unnormalized table which repeats
for the key attribute(s).
• If partial dependencies exist on the primary key remove them by placing then in
a new relation along with a copy of their determinant.
Not 2NF Example:
Because:
• Partial Dependency: (attributes depend on part of composite key).
• Customer No → Cname
• Prop No → Paddress, OwnerNo, OwnerName.
• Update Anomalies In 2NF:
• Much less redundancy now but anomalies still exist e.g if we want to update
name of an owner, such as Tony Show, we still have to update 2 rows in
property relation (as he owns 2 properties) 3NF will remove such anomalies.
• 3NF Definition:
• A relation that is in 1NF and 2NF and in which no non-primary-key attribute
is transitively dependent on the primary key.
• To normalize a relation from 2NF to 3NF
- Identify the primary key in the 2NF relation.
- Identify functional dependencies in the relation.
• If transitive dependencies exist on the primary key remove them by placing them
in a new relation along with a copy of their dominant, Consider previous example
Property_Owner ProNo Address Rent OwnerNo OwnerName
- PropNO → Owner No
- Owner No → Owner Name
- Transitive dependency of OwnerName on PropNO through OwnerNO.
• To convert to 3NF, remove this attribute (OwnerName) and place in new relation
with the attribute it depends on (determinant).
- PROP_FOR_RENT (PropNO Padd, Rent, OwnerNO)
- OWNER (OwnerNo, OwnerName).
Process of Decomposition
FDs for Customer_Rental Relation
PROF-COURSE Table
PROF-COURSE Unnormalized
CREDIT-
PROF-NO NAME OFFICE-NO PHONE-NO COURSE-NO DESCRIPTION DAY-PREF TIME-PREF
HOURS
3
ACCT427 AIS MW 8 am
Dr.
1001 401A 5-5515 ACCT 648 Advanced AIS 1 MW 2 pm
Benton
COMP101 Software tools MWF 11 am
3
3
ACCT327 Intermediate I MWF 10 am
1003 Dr. Ross 402G 2-6785
ACCT 328 Intermediate II TR 10 am
3
3
ACCT427 AIS MW 10 am
1004 Dr. Green 401Z 5-9111
ACCT 209 Principles TR 9 am
3
First Normal Form
• A relation that is said to be in first normal
form (1NF) when there is exactly one value
in each cell - at the intersection of a row and
a column.
• Therefore there are no repeating groups
PROF-COURSE Table Make a
Unnormalized new table
with these
PROF-COURSE fields
CREDIT-
OFFICE-
PROF-NO NAME PHONE-NO COURSE-NO DESCRIPTION DAY-PREF TIME-PREF
NO
HOURS
3
ACCT427 AIS MW 8 am
1001 Dr. Benton 401A 5-5515 ACCT 648 Advanced AIS 1 MW 2 pm
COMP101 Software tools MWF 11 am
3
3
ACCT327 Intermediate I MWF 10 am
1003 Dr. Ross 402G 2-6785
ACCT 328 Intermediate II TR 10 am
3
3
ACCT427 AIS MW 10 am
1004 Dr. Green 401Z 5-9111
ACCT 209 Principles TR 9 am
3
Repeating Groups
PROF-COURSE Relational Database
First Normal Form (1NF)
PROF
COURSE-PREF(1NF)
COURSE-PREF(1NF)
PROF table is
PROF
1001
1002
Dr. Benton
Dr. Carter
401A
401B
5-5515
5-8761
already 2NF (it
1003 Dr. Ross 402G 2-6785
has a single
primary key)
1004 Dr. Green 401Z 5-9111
COURSE-PREF(1NF)
Make a
1001 ACCT427 AIS 3 MW 8 am
1004
ACCT328
ACCT427
Intermediate II
AIS
3
3
TR
MW
10 am
10 am
fields
1004 ACCT209 Principles 3 TR 9 am
ACCT427 AIS 3
ACCT209 Principles 3
ACCT327 Intermediate I 3
ACCT328 Intermediate II 3
COURSE-PREF
1001 ACCT427 MW 8 am
1001 ACCT648 MW 2 pm
1002 ACCT209 TR 3 pm
1003 ACCT328 TR 10 am
1004 ACCT427 MW 10 am
1004 ACCT209 TR 9 am
Third Normal Form
• A relation that is said to be in third normal
form (3NF) when:
– It is 2NF, and
– Every secondary key field is functionally
dependent on only the primary key (and not on
any other field in the table)
PROF-COURSE Relational Database
Creating Third Normal Form
PROF-INFO (3NF)
Foreign Key
PROF-NO NAME OFFICE-NO*
Primary Key
OFFICES (3NF)
OFFICE-NO PHONE-NO
401A 5-5515
401B 5-8761
402G 2-6785
401Z 5-9111
Database Normalization
Foreign Keys
• A secondary field in one table that is the
same as the primary key in another table is
called a foreign key.
• (Just like primary key – primary key links)
Foreign key to primary key links allow
tables to be merged so query information
can be extracted from the database.
PROF-COURSE Relational Database
These tables are already Third Normal Form
COURSES (3NF)
ACCT427 AIS 3
ACCT209 Principles 3
ACCT327 Intermediate I 3
ACCT328 Intermediate II 3
COURSE-PREF (3NF)
1001 ACCT427 MW 8 am
1001 ACCT648 MW 2 pm
1002 ACCT209 TR 3 pm
1003 ACCT328 TR 10 am
1004 ACCT427 MW 10 am
1004 ACCT209 TR 9 am
PROF-COURSE Relational Database
Third Normal Form – 4 tables from 1
PROF-INFO (3NF)
OFFICES (3NF)
PROF-COURSE OFFICE-NO PHONE-NO
401A 5-5515
CREDIT-
OFFICE-
PROF-NO NAME PHONE-NO COURSE-NO DESCRIPTION DAY-PREF TIME-PREF 401B 5-8761
NO
HOURS
402G 2-6785
3
ACCT427 AIS MW 8 am 401Z 5-9111
1001 Dr. Benton 401A 5-5515 ACCT 648 Advanced AIS 1 MW 2 pm
COMP101 Software tools MWF 11 am
3
COURSES (3NF)
1002 Dr. Carter 401B 5-8761 ACCT209 Principles 3 TR 3 pm
COURSE-NO DESCRIPTION CREDIT-HOURS
3
ACCT327 Intermediate I MWF 10 am ACCT427 AIS 3
1003 Dr. Ross 402G 2-6785
ACCT 328 Intermediate II TR 10 am
3
ACCT648 Advanced AIS 3
3 ACCT209 Principles 3
ACCT427 AIS MW 10 am
1004 Dr. Green 401Z 5-9111
ACCT 209 Principles TR 9 am
3 ACCT327 Intermediate I 3
ACCT328 Intermediate II 3
COURSE-PREF (3NF)
1001 ACCT427 MW 8 am
1001 ACCT648 MW 2 pm
1002 ACCT209 TR 3 pm
1003 ACCT328 TR 10 am
1004 ACCT427 MW 10 am
1004 ACCT209 TR 9 am
Summary of the Rules for Normal Forms
• 1NF if there are no repeating groups in the
relation
• 2NF if every secondary key field is
functionally dependent on the entire primary
key
• 3NF if all functional dependencies in the
relation originate from the primary key (no
transitive dependencies)
PROF-COURSE Relational Database
Schema of the Relation
• 3NF to BCNF
- Identify all candidate keys in the relation.
- Identify all functional dependencies in the relation.
•If functional dependencies exists in the relation where their determinants are not candidate keys
for the relation, remove the functional dependencies by placing them in a new relation along with a
copy of their determinant.
filmNo fTitle dirNo director actorNo aName role timeOnScreen
F1100 Happy
Days D101 Jim Alan A1020 Sheila Toner Jean Simson 15.45
F1100 Happy D101 Jim Alan A1020 Sheila Toner Jean Simson 15.45
Days
F1100 Happy D101 Jim Alan A1222 Peter Watt Tom Kinder 25.38
Days
F1100 Happy D101 Jim Alan A1020 Sheila Toner Silvia 22.56
Days Simpson
F1109 Snake Bite D076 Sue A1567 Steven Tim Rosey 19.56
Ramsay McDonald
F1109 Snake Bite D076 Sue A1222 Peter Watt Archie Bold 10.44
Ramsay
filmNo fTitle dirNo director actorNo aName role timeOnScreen
fd1
fd2
fd2
dirNo director