0% found this document useful (0 votes)
52 views28 pages

DB Lec 5+6 Normalization

Uploaded by

Adnan Asif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views28 pages

DB Lec 5+6 Normalization

Uploaded by

Adnan Asif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Lecture 5+6

Normalization
Normalization

The process of decomposing relations with anomalies to

produce smaller, well structured relations.

2
Well-Structured Relations

 A relation that contains minimal data redundancy and

allows users to insert, delete, and update rows without

causing data inconsistencies.

 Goal is to avoid anomalies.

3
Anomalies
 An error or inconsistency that may result when a user
attempts to update a table that contains redundant data.
The three types of anomalies are:
 Insertion Anomaly–adding new rows forces user to create duplicate
data
 Deletion Anomaly–deleting rows may cause a loss of data that
would be needed for other future rows
 Modification Anomaly–changing data in a row forces changes to
other rows because of duplication
Example

Question–Is this a relation? Answer–Yes: Unique rows and no multi-


valued attributes

Question–What’s the primary key? Answer–Composite: Emp_ID, Course_Title

5
Anomalies in this Table
 Insertion–can’t enter a new employee without having the

employee take a class

 Deletion–if we remove employee 140, we lose

information about the existence of a Tax Acc class

 Modification–giving a salary increase to employee 100

forces us to update multiple records


6
Normalization Goals
 Minimize data redundancy, thereby avoiding anomalies and

conserving storage space.

 Simplify the enforcement of referential integrity constraints

 Make it easier to maintain data (insert, update and delete)

 Provide a better design that is an improved representation

of the real world and a stronger basis for future growth.


Steps in Normalization
 Normalization can be accomplished and understood in

stages, each of which corresponds to a normal form.

 Normal form: a state of a relation that results from

applying simple rules regarding functional dependencies(or

relationships between attributes) for relationships between

attributes to that relation.


Steps in Normalization

9
Functional Dependencies and Keys
 Functional Dependency: The value of one attribute (the determinant)
determines the value of another attribute

 Candidate Key:

 A unique identifier. One of the candidate keys will become the


primary key
 E.g. perhaps there is both credit card number and SS# in a
table…in this case both are candidate keys
 Each non-key field is functionally dependent on every candidate key

10
First Normal Form
 There are no repeating groups in the relation (thus, there is

a single fact at the intersection of each row and column of

the table).

 A primary key has been defined, which uniquely identifies

each row in a relation.

11
Table with multivalued attributes, not in 1st normal form

Note: this is NOT a relation

12
Convert to 1NF
 Remove repeating groups
Convert to 1NF
 There are four determinants in INVOICE, and their

functional dependencies are the following:


 Order_ID  Order_Date,Customer_ID,Customer_Name,

Customer_Address

 Customer_ID  Customer_Name, Customer_Address

 Product_ID  Product_Description, Product_Finish, Unit_Price

 Order_ID, Product_ID  Ordered_Quantity


Convert to 1NF
Functional Dependency Diagram
Table with no multivalued attributes and unique rows, in 1st
normal form

Note: this is relation, but not a well-structured one


16
Anomalies in this Table
 Insertion–if new product is ordered for order 1007 of existing

customer, customer data must be re-entered, causing duplication

 Deletion–if we delete the Dining Table from Order 1006, we lose

information concerning this item's finish and price

 Update–changing the price of product ID 4 requires update in

several records

17
Second Normal Form
 1NF PLUS 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

18
Convert To 2NF
Partial Functional Dependency

A functional dependency in which one or more non key

attributes are functionally dependent on part (but not all) of the

primary key.
Convert To 2NF
 Functional Dependency Diagram
Convert To 2NF
 Steps to Convert relation from 1NF to 2NF

 Create a new relation for each primary key attribute (or


combination of attributes) that is determinant in a partial
dependency. The attribute is the primary key in the new
relation.
 Move the non-key attributes that are dependent on this primary
key attribute (or attributes) from the old relation to the new
relation.
Convert To 2NF
 Functional Dependency Diagram
Convert To 2NF
 A relation in 1NF will be in 2NF if anyone of the
following conditions apply
 The primary key consists of only one attribute.
By definition there can not be a partial
dependency in such a relation
 No non key attributes exist in the relation. There
are no functional dependencies in such a relation.
 Every non key attribute is functionally dependent
on the full set of primary key attributes.
Third Normal Form

2NF PLUS no transitive dependencies.

24
Convert to 3NF
Transitive Dependency

A functional dependency between two (or more) non

key attributes.
Convert to 3NF
 Functional Dependency Diagram
Convert to 3NF
 Steps to convert relation from 2NF to 3NF

 For each non key attribute (or set of attributes) that is determinant in

a relation, create a new relation. That attribute (or set of attributes)


becomes the primary key of the new relation.
 Move all of the attributes that are functionally dependent on the

attribute from the old to the new relation.


 Leave the attribute (which serve as a primary key in new relation) in

the old relation to serve as a foreign key that allow you to associate
the two relations.
Convert to 3NF
 Functional Dependency Diagram

You might also like