0% found this document useful (0 votes)
5 views

Normalization(V2)

Uploaded by

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

Normalization(V2)

Uploaded by

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

Database

Mapping &
Normalizatio
n Third Learning
Outcome
Agenda
• Why Normalization
• Type of Anomalies
• Functional Dependency
• What is Normalization
• What role it plays in database
design
• 1st. Normal Form
• 2nd. Normal Form
• 3rd. Normal Form
• BC Normal Form (BCNF)
Why Normalization
To produce well-structured relations by eliminating anomalies
• Make the database more efficient

• Prevent the same data from being stored in more than one place (called an “insert

anomaly”)

• Prevent updates being made to some data but not others (called an “update anomaly”)

• Prevent data not being deleted when it is supposed to be, or from data being lost when

it is not supposed to be (called a “delete anomaly”)

• Ensure the data is accurate

• Reduce the storage space that a database takes up

• Ensure the queries on a database run as fast as possible


Type of Anomalies
Data Anomalies
An anomaly is where there is an issue in the data that is not meant to be there.
This can happen if a database is not normalized.
• Update (Modification) Anomaly
Changing data in a row forces changes to other rows because of
duplication
• Deletion Anomaly
Deleting rows may cause a loss of data that would be needed for other
future rows
• insertion Anomaly
if the schema is not
Adding new rows forces user to create normalized, it will
duplicate data definitely contain
anomalies
Example ..
We’ll be using a student database as an example which records
student, class, and teacher information.

Let’s say our student database looks like this:


Insertion anomaly
An insert anomaly happens when we try to insert a record into this table
without knowing all the data we need to know.

For example, if we wanted to add a new student but did not know their
course name.

The new record would look like this:


Update anomaly
An update anomaly happens when we want to update data, and we update some of
the data but not other data.

For example, let’s say the class Biology 1 was changed to “Intro to Biology”. We would
have to query all of the columns that could have this Class field and rename each one
that was found.

There’s a risk that we miss out on a value, which would cause issues.
Delete anomaly
A delete anomaly occurs when we want to delete data from the table, but we end up
deleting more than what we intended.

For example, let’s say Susan Johnson quits and her record needs to be deleted from
the system. We could delete her row:
But, if we delete
this row, we lose
the record of the
Biology 2 class,
because it’s not
stored anywhere
else. The same can
be said for the
Medicine course.
Type of Anomalies

Let's Watc
h if the schema is not
normalized, it will
definitely contain
anomalies
Functional Dependency
As we said before, normalization solves anomalies ,,
but what is Normalization ?
Normalization is based on

Functional Dependency: The value of one attribute determines the value of another
attribute

• All the attributes should be separated as Key-attributes and Non-key attributes


• All the non-key attributes should be fully functional depending on the key-
attributes. P Searc
• Which means if I search about something with the Primary KeyKattributeh it
Single Nul
should output a single-valued non-key attributes at single table
Record l
What Are The Normal Forms?
The process of normalization involves applying rules to a set of data. Each of
these rules transforms the data to a certain structure, called a normal form.

There are three main normal forms that you should consider
(Actually, there are six normal forms in total, but the first three
are the most common).

Whenever the first rule is applied, the data is in “first normal


form“. Then, the second rule is applied and the data is in “second
normal form“. The third rule is then applied and the data is in
P Searc
“third normal form“.
K h
Single Nul
Record l
Fourth and fifth normal forms are then achieved from their
1st. Normal Remove repeating Groups

Form
To be in First Normal Form (1NF):

• Each column must contain only a single value

• Repeating groups of records (redundancy) must be


eliminated

• Eliminate duplicative columns from the same table.

• There must not be a composite and a multi-valued


1NF Example
Test your memory!!

What does Functional Dependency mean?


Remove Partial

2nd. Normal Dependency

Form
To be in Second Normal Form (2NF):

• Any attributes must not be dependent on a portion of primary


key.

• The other way to understand 2NF is that each non-key attribute


(not a part of PK) in the relation must be functionally dependent
upon the primary key.
Remove Hidden

3rd. Normal Dependency (transitive


dependency)

To Form
be in third Normal Form (3NF):

• All attributes that are not dependent upon the primary key must
be eliminated. In other words, there should be no transitive
dependencies.

• remove columns that are not dependent upon the primary key.

In other Words ...


It means that every attribute that is not the primary key must depend on the
primary key and the primary key only.
Test your memory!!

What is Normalization ? Why do we apply


Normalization to the DB ?
Boyce-Codd Normal Form
(BCNF)
• Special case of 3NF.

• A relation is in BCNF if it’s in 3NF and there is no hidden


dependencies.

• Below is in 3NF but not in BCNF


Boyce-Codd Normal Form
(BCNF)
• Example
Remove Multi-Valued

4rth. Normal attributes

Form
To be in Forth Normal Form (4NF):

• remove multi-valued attributes


Test your memory!!

Write the stages of Normalization with brief


explanation in 5 mins
Let’s go deeper ..
Consider
• Invoice No.
• Date
this
1/8/2024
Data
1234
View (Sample of Data )
• Customer ID 1
• Customer Name Ahmed
• Customer Phone 0112211/010223322
• Products
Note!
Unit
Code Name
Price
Quantity Data are Just to
understand
q10 Oil 5 20
functional
T2 Milk 10 2 dependency and
context
• Cahier ID 1
• Cahier Name Ahmed
• Total 120 L.E
Transform to(1NF)
Remove repeating Groups

Invoice
• Invoice No. pk
Inv-Products
• Invoice No. FK
• Date
• Code (comp PK)
• Customer ID
• Customer Name
• Name
• Customer Phones
• Unit Price
• Cashier ID
• Qty
• Cashier Name
• Name
Transform to(2NF) Remove partial
dependency

pass the Invoice as it is Inv-Products


(Single primary key) • Invoice No. FK
• Invoice No. pk • Code (comp PK)
• Date
• Customer ID
• Qty
Products
• Customer Name • Code pk
• Customer Phones • Name
• Cashier ID • Unit Price
• Cashier Name
Transform to(3NF) Remove Hidden
dependency
Invoice
• Invoice No. pk Inv-Products (one non-key
• Date attribute so pass as it is )
• Customer ID
• Invoice No. FK
• Cashier ID
• Code (comp PK)
• Qty

Customer Cashier
• Customer ID pk
• Cashier ID pk Products
• customer name
• cashier name
• customer phones (pass)
• Code pk
• Name
• Unit Price
Transform to(4NF)
Remove multi-valued
attributes
Invoice (pass)
• Invoice No. pk Inv-Products (pass)
• Date Products (pass)
• Invoice No. FK
• Customer ID • Code pk
• Code (comp PK)
• Cashier ID • Name
• Qty
• Unit Price
Cashier (pass)
• Cashier ID pk
Customer
• cashier name Customer/phones
• Customer ID pk • Customer ID fk
• customer name • customer phone
(comp pk)
Normalization and Database
Design

• Normalization should be part of the design process

• E-R Diagram provides macro view


• Normalization provides micro view of entities

• Generally, most database designers do not attempt to implement


anything higher than Third Normal Form or Boyce-Codd Normal Form.
Thank You.
Thank You.
Thank You.

You might also like