Sie sind auf Seite 1von 37

IF41204 - IF31204

Normalization

Pengenalan Basisdata
Togu Turnip - Institut Teknologi Del
Minggu 10 Sesi 01
AGENDA
1 What is normalization

2 Goals of normalization

3 Functional Dependency

4 Normalization by levels : 1NF, 2NF, 3NF

5 Denormalization

1
What is
Normalization?
Normalization
• Normalization is the process for evaluating and correcting
relation structures to minimize data redundancies.
• Normalization is a database design technique which
organizes tables in a manner that reduces redundancy and
dependency of data.
• A process that goes by levels, refining the design each time
• Although we deals with relation, the refinement is mostly on
the relationship level.
Normalization
• So what’s the point?
• Each level reduces more redundancy
• Each level also makes DB operation slower
• In other words, It divides larger tables to smaller tables and
links them using relationships.
• There are many levels of normalization, but the typical
stopping point is the 3 (3NF)
rd
The History of Normalization
• The inventor of the relational model Edgar Codd
proposed the theory of normalization with the
introduction of First Normal Form.
• He continued to extend theory with Second and
Third Requirement
Normal Form.StagesRequirement Stages
• Later he joined with Raymond F. Boyce to develop
the theory of Boyce-Codd Normal Form.

Requirement Stages
2 The Goal of
Normalization
Goals of Normalization
• Decide whether a particular relation R is in “good” form.
• In the case that a relation R is not in “good” form, decompose it
into a set of relations {R1, R2, ..., Rn} such that
• each relation is in good form
• the decomposition is a lossless-join decomposition
• A relation represents only a single theme and its attributes
• Data should be kept in one relation where possible (controlled
redundancy) to eliminate update anomalies
• All data in a row must depend on the PK
Modification Anomaly
• No update, insertion, or deletion anomalies so
integrity and consistency is ensured
• Our theory is based on:
• functional dependencies
• Relations are categorized as a normal form based
on which modification anomalies or other problems
they are subject to:
Example: Update Anomaly
• The
EQUIPMENT_REPAIR
table before and after
an incorrect update
operation on
AcquisitionCost for
Type = Drill Press:
Normal Form

Requirement Stages
3

Functional Dependency
* See the previous slide

4
Normalization by
Levels
1NF - 3NF
• Normalization that will be covered in these course:
• 1NF : No repeating elements or group of elements
• 2NF : No partial dependencies on a concatenated
key
• 3NF : No dependencies on non-key attributes
• Rule if the normalization fails:
“create a new table”
Problem:

Keeping Track of A Stack of Invoices
1 NF
• No repeating elements or group of elements
• Repeating group multiple entries exist for the same key
Step-by-Step 1 NF

• Those of us who have an ordered mind but aren’t quite aware of relational databases
might try to capture the Invoice data in a spreadsheet, such as Microsoft Excel
• Try to answer these questions:
• How many 3” Red Freen did Freen R Us order in 2002?
• What are total sales of 56” Blue Freens in the state of Texas?
• What items are sold on July 14, 2003?
• As the spreadsheet grows, it becomes increasingly difficult to ask the spreadsheet these
questions, we begin the NORMALIZATION process
Step-by-Step 1 NF

• Back to figure A-1


• Invoice #125 , cells H2-H4 contains list of item ID numbers, same with
columns I2-I4, J2-J4, K2-K4, L2-L4, M2-M4.
• Each of these columns contains a list of value
• A list of value 1NF objects to (or fails 1NF)
• Conclusion : The invoice fails the 1NF create a new tabel
Step-by-Step 1 NF

• Solutions:
• Create a new table, in which
• The first table : keep the attributes that doesn’t fail 1NF
• The second table : attributes that fails the 1NF, but the PK will be
concatenated(composite) key (key from non-fails attributes and key of fails
attributes).
The Result of 1 NF

Orders

Order_Items
2 NF
• A relation is in 2NF if all of its non-key attributes are
dependent on all of the primary keys.
• No partial dependencies on a concatenated key.
Step-by-Step 2 NF
• Questions:
• Do we have table with concatenated key?
• Named Tables with no concatenated key, is in 2NF
• Tables with concatenated key, we should check whether there
are partial dependencies on a concatenated key.
• From 1NF:
• Orders : is in 2NF
• Order_Items : check for 2NF
Step-by-Step 2 NF

• Questions:
• Is item_description wholly depends on order_id and item_id?
Or partiallly?
• Is item_qty wholly depends on order_id and item_id? Or
partiallly ?
• Is item_price wholly depends on order_id and item_id? Or
partiallly ?
Step-by-Step 2 NF
• Analysis
• If wholly depends than NO PROBLEM
• If any attributes are partially depend on PK then, it fails 2NF
Create a new table
• Solution
• Create a new table from Order_Items in which the new table
consists of attributes that fails and its PK.
The Result of 2 NF

So, now we have tables:


1.Order_Items
2.Items
3.Orders (from 1NF that doesn’t fail 2NF)
3 NF
• No dependencies on non-key attributes
• A relation is in 3NF if and only if it is in 2NF and there are no
non-key attributes determined by another non-key attribute.
• However, the term non-key attribute means an attribute that is
neither
• (1) a candidate key itself, nor
• (2) part of a composite candidate key.
Example: Participation Constraints
• Check the result of the 2NF
• Ask : Are there dependencies on non-key attributes?
Question for The 3 NF
• Consider Table Orders:
• Order_Date : can it exists without order id?
• Customer_name : can it exists on its own, outside the order
tables?
Solution for 3 NF
• Solutions:

• But, in 3NF the new customer tables doesn’t have relationship


with any other tables:
• SOLUTION to Remember : in 3NF, the new table will have it’s
PK as FK in the tables that fails the 3NF, So:
The Final Relations

5
Denormalization
Denormalization
• For read-only databases, normalization is seldom an advantage.
• Application processing speed is more important.
• Denormalization is the joining of the data in normalized tables
prior to storing the data.
• The data is then stored in non-normalized tables.
Normalized Tables Denormalized Table
Summary
Exercise
References
• DAVID M. KROENKE’S DATABASE CONCEPTS, 2nd
Edition, 2005 Pearson Prentice Hall
• Silberschatz, Korth and Sudarshan, Database System
Concepts, 6 th Ed.
• Slide was adapted from RSL (2016) for Introduction to
Database course
THANK YOU!
DON’T FORGET TO BE AWESOME

Das könnte Ihnen auch gefallen