Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Normalization of Database Tables

Introduction to Introduction to
l Objectives
Normalization Normalization
of
Database
of
Database
4 The idea of Dependencies of Attributes
Tables
Normalization of Database Tables Tables
4 Normalization and Database Design
4 Understand concepts of normalization
(Higher-Level Normal Forms)
ISM 602 4 Learn how to normalize tables
Dr. Hamid Nemati 4 Understand normalization and database
design issues
4 Denomalization

Functional Dependency Examples of Functional Dependencies:


l A Functional Dependency Is A Relationship Between l If we know an ISBN, then we know the Book Title and
Or Among Attributes Such That The Values Of One the author(s)
Introduction to Introduction to
Normalization Attribute Depend On, Or Are Determined By, The Normalization l ISBN è Book Title
of of
Database Values Of The Other Attribute(s). Database
l ISBN è Author(s)
Tables Tables
l Partial Dependency: Is A Relationship Between l If we know the VIN, then we know who is the Auto
Attributes Such That The Values Of One Attribute Is owner
Dependent On, Or Determined By, The Values Of
l VIN è Auto_Owner
Another Attribute Which Is Part Of The Composite Key.
l Partial Dependencies Are Not Good Due To duplication l If we know Student-ID (SID), then we can uniquely
Of Data And Update Anomalies; determine his/her Name
l SID è S_Name

Transitive Dependencies So Now what is Normalization?


l Is A Relationship Between Attributes Such That The l GOLDEN RULE OF NORMALIZATION: Enter The
Values Of One Attribute Is Dependent On, Or Minimum Data Necessary, Avoiding Duplicate Entry
Introduction to Introduction to
Normalization Determined By, The Values Of Another Attribute Normalization Of Information, With Minimum Risks To Data
of of
Database Which Is Not A Part Of The Key. Database Integrity.
Tables Tables
l Exist when a nonkey attribute value is functionally l Goals Of Normalization:
dependent upon another nonkey value in the record. For u Eliminate Redundancies Caused By:
example: l Fields Repeated Within A File
l EMPLOYEE_ID --> JOB_CATEGORY l Fields Not Directly Describing The Key Entity
l JOB_CATEGORY --> HOURLY_RATE l Fields Derived From Other Fields
l An employee data table that includes the “hourly pay u Avoid Anomalies In Updating (Adding, Editing,
rate” would require searching every employee record to Deleting)
properly update an hourly rate for a particular job u Represent Accurately The Items Being Modeled
category. u Simplify Maintenance And Retrieval Of Info
Database Tables and Normalization Basic Rule for Normalization

l Normalization is a process for assigning attributes l The attribute values in a relational table should
Introduction to
to entities. It reduces data redundancies and helps Introduction to
be functionally dependent (FD) on the primary
Normalization
of
eliminate the data anomalies. Normalization
of
key value.
Database Database
Tables l Normalization works through a series of stages Tables u A relationship is functionally dependent when one
called normal forms: attribute value implies or determines the attribute
u First normal form (1NF) value for the other attribute.
l EM_SS_NUM --> EM_NAME
u Second normal form (2NF)
l Corollaries
u Third normal form (3NF)
u Corollary 1: No repeating groups allowed in
l The highest level of normalization is not always relational tables.
desirable.
u Corollary 2: A relational table should not have
attributes involved in a transitive dependency
relationship with the primary key.

Normalization Benefits Database Tables and Normalization


l Facilitates data integration. l The Need for Normalization
Introduction to l Reduces data redundancy. Introduction to
u Case of a Construction Company
Normalization Normalization
l Building project -- Project number, Name, Employees
of
Database
l Provides a robust architecture for retrieving of
Database assigned to the project.
Tables
and maintaining data. Tables
l Employee -- Employee number, Name, Job classification
l Compliments data modeling. l The company charges its clients by billing the hours spent
on each project. The hourly billing rate is dependent on the
l Reduces the chances of data anomalies employee’s position.
occurring.

Database Tables and Normalization Deletion Anomaly

l Problems with the Table 5.1 l Occurs when the removal of a record results in a
Introduction to
u The project number is intended to be a primary key, Introduction to loss of important information about an entity.
Normalization
of
but it contains nulls. Normalization
of l Example:
Database Database
Tables u The table displays data redundancies. Tables l All the information about a customer is contained in an order
u The table entries invite data inconsistencies. file, if the order is canceled, all the customer information
could be lost when the order record is deleted
u The data redundancies yield the following
anomalies: l Solution:
l Update anomalies. l Create two tables--one table contains order information and
the other table contains customer information.
l Addition anomalies.
l Deletion anomalies.
Update Anomaly Insertion Anomaly
l Occurs when a change of a single attribute in one l Occurs when there does not appear to be any
Introduction to record requires changes in multiple records Introduction to reasonable place to assign attribute values to
Normalization Normalization
of l Example: of records in the database. Probably have
Database Database
Tables
uA staff person changes their telephone number Tables overlooked a critical entity.
and every potential customer that person ever l Example:
worked with has to have the corrected number u Adding new attributes or entire records when they
inserted. are not needed. Where do you place information
l Solution: on new Evaluator’s? Do you create a dummy
u Put the employees telephone number in one Lead.
location--as an attribute in the employee table. l Solution:
u Create a new table with a primary key that
contains the relevant or functional dependent
attributes.

Database Tables and Normalization Database Tables and Normalization


l Conversion to First Normal Form l Dependency Diagram
Introduction to
u A relational table must not contain repeating groups. Introduction to
u The arrows above the entity indicate that the entity’s
Normalization
of u Repeating groups can be eliminated by adding the
Normalization
of
attributes are dependent on the combination of
Database
Tables appropriate entry in at least the primary key Database
Tables
PROJ_NUM and EMP_NUM.
column(s). (See Database Table 5.3) u The arrows below the dependency diagram indicate
less desirable dependencies based on only a part of
the primary key -- partial dependencies.

Database Table 5.2 The Evergreen Data


Figure 5.1 A Dependency Diagram: First Normal Form

Database Tables and Normalization Database Tables and Normalization


l 1NF Definition l Conversion to Second Normal Form
Introduction to
u The term first normal form (1NF) describes the Introduction to
u Starting with the 1NF format, the database can be
Normalization
of
tabular format in which: Normalization
of
converted into the 2NF format by
Database Database
Tables
l All the key attributes are defined. Tables
l Writing each key component on a separate line, and then
l There are no repeating groups in the table. writing the original key on the last line and
l All attributes are dependent on the primary key. l Writing the dependent attributes after each new key.

PROJECT (PROJ_NUM, PROJ_NAME)


EMPLOYEE (EMP_NUM, EMP_NAME, JOB_CLASS,
CHG_HOUR)
ASSIGN (PROJ_NUM, EMP_NUM, HOURS)
Database Tables and Normalization Database Tables and Normalization
l 2NF Definition l Conversion to Third Normal Form
Introduction to
u A table is in 2NF if: Introduction to
u Create a separate table with attributes in a transitive
Normalization
of l It is in 1NF and Normalization
of
functional dependence relationship.
Database Database
Tables l It includes no partial dependencies; that is, no Tables
attribute is dependent on only a portion of the primary PROJECT (PROJ_NUM, PROJ_NAME)
key. ASSIGN (PROJ_NUM, EMP_NUM, HOURS)
u Note: EMPLOYEE (EMP_NUM, EMP_NAME, JOB_CLASS)
It is still possible for a table in 2NF to exhibit JOB (JOB_CLASS, CHG_HOUR)
transitive dependency; that is, one or more attributes
may be functionally dependent on nonkey attributes.
u See figure 5.2 page 290.

Database Tables and Normalization Normalization and Database Design


l 3NF Definition l Database Design and Normalization Example:
Introduction to
u A table is in 3NF if: Introduction to
(Construction Company)
Normalization Normalization
of l It is in 2NF and of u Summary of Operations:
Database Database
Tables l It contains no transitive dependencies. Tables l The company manages many projects.
l Each project requires the services of many employees.
l An employee may be assigned to several different projects.
l Some employees are not assigned to a project and perform
duties not specifically related to a project. Some employees
are part of a labor pool, to be shared by all project teams.
l Each employee has a (single) primary job classification.
This job classification determines the hourly billing rate.
l Many employees can have the same job classification.

Normalization and Database Design Normalization and Database Design


l Two Initial Entities: l Three Entities After Transitive Dependency
Introduction to
PROJECT (PROJ_NUM, PROJ_NAME)
Introduction to
Removed
Normalization EMPLOYEE (EMP_NUM, EMP_LNAME, EMP_FNAME, Normalization PROJECT (PROJ_NUM, PROJ_NAME)
of of
Database EMP_INITIAL, JOB_DESCRIPTION, Database EMPLOYEE (EMP_NUM, EMP_LNAME, EMP_FNAME,
Tables Tables
JOB_CHG_HOUR) EMP_INITIAL, JOB_CODE)
JOB (JOB_CODE, JOB_DESCRIPTION,
JOB_CHG_HOUR)

Figure 5.7 The Initial E-R Diagram for a Contracting Company


Normalization and Database Design Normalization and Database Design
l Creation of the Composite Entity ASSIGN
Introduction to Introduction to
Normalization Normalization
of of
Database Database
Tables Tables

Figure 5.8 The Modified E-R Diagram for a Contacting Company


Figure 5.9 The Final (Implementable) E-R Diagram
for the Contracting Company

Normalization and Database Design Normalization and Database Design


l Attribute ASSIGN_HOUR is assigned to the
Introduction to
composite entity ASSIGN. Introduction to
Normalization Normalization
of l “Manages” relationship is created between of
Database Database
Tables EMPLOYEE and PROJECT. Tables

PROJECT (PROJ_NUM, PROJ_NAME, EMP_NUM)


EMPLOYEE (EMP_NUM, EMP_LNAME, EMP_FNAME,
EMP_INITIAL, EMP_HIREDATE, JOB_CODE)
JOB (JOB_CODE, JOB_DESCRIPTION,
JOB_CHG_HOUR)
ASSIGN (ASSIGN_NUM, ASSIGN_DATE, PROJ_NUM,
EMP_NUM, ASSIGN_HOURS)

Figure 5.10 The Relational Schema for the Contracting Company

Summary
Denormalization
A Journey of Normalization
First Normal Form Remove l Normalization is only one of many database design
(1NF) “Repeating Groups” goals.
Introduction to Introduction to
Normalization Normalization
of of l Normalized (decomposed) tables require additional
Database Remove Database
Tables Second Normal Form “Partial Functional Tables processing, reducing system speed.
(2NF) Dependency” l Normalization purity is often difficult to sustain in
Remove the modern database environment. The conflict
Third Normal Form “Transitive Functional between design efficiency, information
(3NF) Dependency” requirements, and processing speed are often
resolved through compromises that include
Remove
denormalization.
Higher order Normal “All Remaining Functional
Forms Dependency”

You might also like