Topic 07
Topic 07
1
Reminder:
Intellectual Property
◼ Copyright must be seriously protected. The University
takes a strong stand against any illegal photocopying and
distributing of all materials provided to students. Students
are forewarned of the consequences and the penalty that
may be meted out if they are “caught in the act”.
◼ All the materials provided to student SHOULD NOT be
posted/distributed at any online platform or any other
ways possible without the permission.
Objectives
◼ How tables that contain redundant data can suffer from update
anomalies, which can introduce inconsistencies into a database.
◼ Identification of various types of update anomalies such as
insertion, deletion, and modification anomalies.
◼ Purpose of normalization.
◼ The rules associated with the most commonly used normal forms,
namely first (1NF), second (2NF), and third (3NF).
3
Purpose
4
The Evils of Data redundancy
5
Data redundancy
StaffBranch table has redundant data; the details of a branch are repeated
for every member of staff.
6
Data redundancy Resolved
7
Data redundancy and update anomalies
◼ Tables that contain redundant information may
potentially suffer from update anomalies.
8
Example
9
Insertion anomalies
10
Deletion anomalies
11
Modification anomalies
12
EmpNo EmployeFirst Child1 Child2 child3
3 Mary Zoe
4 Susan
Donor Donation 1 Donation 2 Donation 3 Donation 4
Angel Pinelli
421-99-1243
Victor Gomez $100 Pear Creek $100 DanubeLand $50 Forest Asia
351-12-9867 (Cleaning up litter Trust (Planting trees in
and pollutants from (Purchasing and Asia) 4/1/2016
Pear Creek) preserving land in
11/6/2015 the Danube
watershed)
24/12/2015
Jack Lee $150 Forest Asia $150 Forest Asia $100 Pear Creek
231-49-0802 ( Planting trees in ( Planting trees in (Cleaning up
Asia) 1/7/2015 Asia) 1/2/2016 litter and
pollutants from
Pear Creek)
1/2/2016
Well-Structured Relations and Data
Normalization
◼ A relation that contains minimal data redundancy
and allows users to insert, delete, and update
rows without causing data inconsistencies
◼ Diagrammatic representation:
19
Unnormalized Form (UNF)
◼ A table that contains one or more repeating
groups
◼ A repeating group is an attribute or group of
attributes, within a table that occurs with
multiple values for a single occurrence of the
nominated key attribute(s) of that table.
◼ To create an unnormalized table:
◼ transform data from information source (e.g.
form) into table format with columns and
rows.
20
Branch table is not in 1NF
21
Relation which is in unnormalized Form
B001 8, Jefferson … 503-555-3618
503-555-2727
503-555-6534
B002 City center plaza, … 206-555-6756
206-555-8836
B003 14-8th Avenue….
First Normal Form
◼ The intersection of every column and record
contains only one value.
◼ There are no repeating groups in the table
◼ All attributes are dependent on primary key
◼ All relational tables satisfy 1NF requirements
◼ Some tables contain partial dependencies
◼ Dependencies based on only part of the primary key
◼ Sometimes used for performance reasons, but should
be used with caution
◼ Still subject to data redundancies
23
UNF to 1NF
24
Branch table is not in 1NF
25
UNF
B001 8, Jefferson … 503-555-3618
503-555-2727
503-555-6534
B002 City center plaza, … 206-555-6756
206-555-8836
B003 14-8th Avenue….
29
Is the table in 1NF?
30
Second Normal Form
◼ a table that is 1NF and every non-key attribute is fully
functionally dependent on the ENTIRE primary key
◼ Every non-key attribute must be defined by the
entire key, not by only part of the key
◼ No partial functional dependencies
32
Is the table in 2NF?
33
34
Third normal form (3NF)
36
2NF to 3NF
37
38
Converting the StaffBranch table to 3NF
More examples
40
The Need for Normalization
41
42
43
Dependency Diagram
FD
FD : Full Dependency
Dependency Diagram
FD
PD
PD
FD : Full Dependency
PD: Partial Dependency
FD : Full Dependency
Dependency Diagram PD: Partial Dependency
FD
PD
PD
PROJECT: PROJECT_EMP:
Projno ProjName Pmgr
Projno Empno HrWorked
EMPLOYEE:
Empno empName JobClass ChgHr
Dependency Diagram
FD
PD
PD
TD
FD : Full Dependency
PD: Partial Dependency
TD: Transitive Dependency
FD : Full Dependency
Dependency Diagram PD: Partial Dependency
TD: Transitive Dependency
FD
PD
PD
TD
PROJECT:
PROJECT_EMP:
Projno ProjName Pmgr
Projno Empno HrWorked
EMPLOYEE: JOB:
Empno empName JobClass ChgHr JobClass ChgHr
Dependency Diagram
FD
PD
PD
TD
FD : Full Dependency
PD: Partial Dependency
TD: Transitive Dependency
Identify and discuss each of the
indicated dependencies.
C1 C2 C3 C4 C5
52
Specify the primary key, foreign key and normal
form
Table
Prima
C1 C2 Forei
Norm
Table
C1 C3 C4 C5 Prima
Foreig
Norma
tab
de
54
Table 1
Primary key: C1
C1 C2 Foreign key: None
Normal form: 3NF
Table 2
C1 C3 C4 C5 Primary key: C1 + C3
Foreign key: C1 (in Table 1)
Normal form: 2NF, because the
table exhibits the transitive
dependencies C4 C5
Specify the primary key, foreign key and
normal form
Table
Prima
C1 C2 Foreig
Norm
Table
Prima
C1 C3 C4 Foreig
Norm
Table
Prima
C4 C5 Foreig
Norm
56
Table 1
Primary key: C1
C1 C2 Foreign key: None
Normal form: 3NF
Table 2
Primary key: C1 + C3
C1 C3 C4 Foreign key: C1 (in Table 1)
C4 (in Table 3)
Normal form: 3NF
Table 3
Primary key: C4
C4 C5 Foreign key: None
Normal form: 3NF