Topic 5 Normalization of Database Tables(Stu)
Topic 5 Normalization of Database Tables(Stu)
Objectives
2
nrnm-UiTM Perak
Database Tables and Normalization
3
Normalization
Process for evaluating and correcting table structures to
minimize data redundancies
◼ Reduces data anomalies
Series of stages called normal forms:
◼ Firstnormal form (1NF)
◼ Second normal form (2NF)
◼ Third normal form (3NF)
nrnm-UiTM Perak
Database Tables and Normalization
4
(cont’d.)
Normalization (continued)
2NF is better than 1NF; 3NF is better than 2NF
For most business database design purposes, 3NF is as
high as needed in normalization
Highest level of normalization is not always most
desirable
Denormalization produces a lower normal form
Increased performance but greater data redundancy
nrnm-UiTM Perak
The Need for Normalization
5
nrnm-UiTM Perak
6
nrnm-UiTM Perak
7
nrnm-UiTM Perak
The Need for Normalization (cont’d.)
8
nrnm-UiTM Perak
Normalization Process
Objective is to ensure that each table conforms to
the concept of well-formed relations
Each table represents a single subject
No data item will be unnecessarily stored in more than
one table
All nonprime attributes in a table are dependent on the
primary key
Each table is void of insertion, update, and deletion
anomalies
Normalization Process
Ensures that all tables are in at least 3NF
Higher forms are not likely to be encountered in
business environment
Normalization works one relation at a time
Starts by:
Identifying the dependencies of a relation (table)
nrnm-UiTM Perak
16
PROJECT(Proj_num,proj_name, Emp_num,emp_name,job_class,Chg_Hour,Hours)
nrnm-UiTM Perak
Conversion to First Normal Form
17
(cont’d.)
Dependency diagram:
Depicts all dependencies found within given table
structure
Helpful in getting bird’s-eye view of all relationships
among table’s attributes
Makes it less likely that you will overlook an important
dependency
nrnm-UiTM Perak
18
nrnm-UiTM Perak
Conversion to First Normal Form
19
(cont’d.)
First normal form describes tabular format:
All key attributes are defined
No repeating groups in the table
All attributes are dependent on primary key
nrnm-UiTM Perak
Conversion to Second Normal Form
20
nrnm-UiTM Perak
21
nrnm-UiTM Perak
Conversion to Second Normal Form
22
(cont’d.)
Table is in second normal form (2NF) when:
It is in 1NF and
It includes no partial dependencies:
◼ No attribute is dependent on only portion of primary key
nrnm-UiTM Perak
Conversion to Third Normal Form
23
nrnm-UiTM Perak
Conversion to Third Normal Form
24
(cont’d.)
Step 2: Reassign Corresponding Dependent
Attributes
Identify attributes dependent on each determinant
identified in Step 1
◼ Identify dependency
Name table to reflect its contents and function
nrnm-UiTM Perak
25
nrnm-UiTM Perak
Conversion to Third Normal Form
26
(cont’d.)
A table is in third normal form (3NF) when both of
the following are true:
It is in 2NF
It contains no transitive dependencies
nrnm-UiTM Perak
Improving the Design
27
nrnm-UiTM Perak
Improving the Design
Evaluate PK assignments and naming conventions
Refine attribute atomicity
Atomic attribute: Cannot be further subdivided
nrnm-UiTM Perak
Surrogate Key Considerations
nrnm-UiTM Perak
Normalization and Database Design
33
nrnm-UiTM Perak
Normalization and Database Design
34
(cont’d.)
ER diagram
Identify relevant entities, their attributes, and their
relationships
Identify additional entities and attributes
Normalization procedures
Focus on characteristics of specific entities
Micro view of entities within ER diagram
nrnm-UiTM Perak
36
nrnm-UiTM Perak
37
nrnm-UiTM Perak
38
nrnm-UiTM Perak
39
nrnm-UiTM Perak
Denormalization
Design goals
Creation of normalized relations
nrnm-UiTM Perak
Data-Modeling Checklist
42
nrnm-UiTM Perak
Table 6.7 - Data-Modeling Checklist
Table 6.7 - Data-Modeling Checklist
(cont’d.)
Table 6.7 - Data-Modeling Checklist
(cont’d.)
Table 6.7 - Data-Modeling Checklist
(cont’d.)
Summary
47
nrnm-UiTM Perak
Summary (cont’d.)
48
nrnm-UiTM Perak
Summary (cont’d.)
49
nrnm-UiTM Perak
50
nrnm-UiTM Perak
51
The dependency diagram in Figure indicates that authors are paid royalties for
each book that they write for a publisher. The amount of the royalty can vary by
author, by book, and by edition of the book.
a. Create a database whose tables are at least in 3NF, showing the dependency
diagram for each table.
nrnm-UiTM Perak
52
nrnm-UiTM Perak
53
nrnm-UiTM Perak
Exercise
54
(Mac 2013)
nrnm-UiTM Perak
Assignment
55
nrnm-UiTM Perak
a. 0NF, contain repeating grp and PK not define yet
b. Primary key : Subject_Code + Birth Certificate Num
57 c.
1NF:
RESULT(Teacher_Code,Teacher_Name,Subject_Code,Subject_Name,
BirthCertificateNo,StudentName,Class_Code, Class,Mark)
2NF
SUBJECT (Subject_Code,Subject_Name,Teacher_Code,Teacher_Name,
STUDENT (BirthCertificateNo,StudentName,Class_Code, Class)
RESULT (Subject_Code, BirthCertificateNo ,Mark)
3NF
SUBJECT (Subject_Code,Subject_Name,Teacher_Code*)
STUDENT (BirthCertificateNo,StudentName,Class_Code*)
RESULT (Subject_Code*, BirthCertificateNo*,Mark)
CLASS (Class_Code,Class)
TEACHER (Teacher_Code,Teacher_Name)
nrnm-UiTM Perak
58
Teach
take
TEACHER
CLASS
PK Teacher_Code
PK Class_Code
Teacher_Name
Class
nrnm-UiTM Perak