Database
Chapter 3: Normalization
Dr. Fatma M. Talaat
Chapter 3 Content:
1. Why Normalize?
2. Normalization
3. Dependencies
4. Normalization Example
2
Chapter 3: Normalization
1. Why Normalize?
• If your database is not normalized, it can be inaccurate,
slow, inefficient.
• It might not produce the data you expect, or want
(update and delete anomalies).
• It makes creating queries, forms, and reports are much
easier to design.
4
• Normalization: sequence of steps by which RDB is both created and improved.
Advantages of Normalization:
1. Get relations in more desirable form.
2. Make database more accurate and efficient.
3. Make creating queries easier.
4. Remove duplication.
2. Normalization
5
• Normalization: sequence of steps by which RDB is both created and improved.
2. Normalization (Normalization Flow)
• A relation is said to be in first normal form if the data is held in a two-
dimensional table with each attribute represented by an atomic value.
• The intersection of a row and a column must contain an indivisible value.
• Each row and column position in the table there exists one value, never a set
of values.
• All attributes are atomic - any single attribute must not be composed of
multiple attributes.
6
First Normal Form (1NF)
The data we would want to store could be expressed as:
Project
No
Project Name Employee No Employee Name Rate
category
Rate
1203 Madagascar
travel site
11 Jessica Brookes A £90
12 Andy Evans B £80
16 Max Fat C £70
1506 Online estate
agency
11 Jessica Brookes A £90
17 Alex Branton B £80
7
First Normal Form (1NF)
• The intersection of a row and a column must contain an
indivisible value
Project
No.
Project Name Employee
No.
Employee
Name
Rate
category
Rate
1203 Madagascar
travel site
11 Jessica
Brookes
A £90
1203 Madagascar
travel site
12 Andy Evans B £80
1203 Madagascat
travel site
16 Max Fat C £70
1506 Online estate
agency
11 Jessica
Brookes
A £90
1506 Online estate
agency
17 Alex Branton B £70
8
Project
No.
Project Name Employee
No.
Solution
Three problems become apparent with our current model:
Tables in a RDBMS use a simple grid structure
• All tables in an RDBMS need a key
• Data entry should be kept to a minimum
• Redundant data
9
First Normal Form (1NF)
10
1NF:
• Relation is said to be in 1NF if data is held in a table with each attribute is
represented by atomic value.
2NF:
• Relation is said to be in 2NF if:
1) It is in 1NF.
2) Remove partial dependency.
Normalization (Normalization Flow)
11
3NF:
• Relation is said to be in 3NF if:
1) It is in 2NF.
2) Remove transitive dependency.
Normalization (Normalization Flow)
12
Partial dependency: when non-key attribute is determined by a part, but not all
composite P.K.
Transitive dependency: when non-key attribute determines another non-key
attribute.
3. Dependencies
• A relation is said to be in second normal form if the relation
(1) is in 1NF and (2) all attributes that are not part of the
primary key are completely functionally dependent on the
primary key. (Partial dependencies must be removed)
• Second Normal Form (2NF) the relation must be in 1NF and each
non key attribute must be fully dependent on the whole key (not a
subset of the key).
13
Second normal form 2NF
Third normal form 3NF
• A relation is said to be in 3NF if it (1) is in 2NF and (2) no
attributes that are not part of the primary key are transitively
dependent on the primary key.
• The key then to move 2NF relations into 3NF is removing any
transitive dependencies that may exist in the relations.
14
Dependencies: Definitions
• Partial Dependency – when an non-key attribute is determined by a
part, but not the whole, of a COMPOSITE primary key.
15
CUSTOMER
Cust_ID Name Order_ID
101 AT&T 1234
101 AT&T 156
125 Cisco 1250
Partial
Dependency
• Transitive Dependency – when a non-key attribute determines
another non-key attribute.
16
EMPLOYEE
Emp_ID F_Name L_Name Dept_ID Dept_Name
111 Mary Jones 1 Acct
122 Sarah Smith 2 Mktg
Transitive
Dependency
Dependencies: Definitions
Example 1
17
• Is the table in the 0NF
18
Studying dependency
1 NF
19
Partial dependency
2 NF
3 NF
20
.
Service Place
Service Type
Service Date
.
12/2002
3/2000
11/99
Service Type
Service Place
Service Type
Transitive Dependency
21
• What is meant by third normal form (3NF)? Examine the following table to
check if it is in 3NF. If yes, explain your answer. Otherwise convert the table
into 3NF.
4. Normalization Example
Client_no CName PropertyNo Address rent_start rent_end rent ownerNo oName
CR76 John kay
PG4
PG16
6 st.G
5 Novar
1-Jul-00
1-Sep-02
31-Aug-01
1-Sep-02
350
450
C040
C093
Tina
Tony
CR56 Aline Set
PG4
PG36
PG16
6 st.G
2 Manor
5 Novar
1-Sep-99
10-oct-00
1-Nov-02
10-Jun-00
1-Dec-01
1-Aug-03
350
370
450
C040
C093
C093
Tina
Tony
Tony
22
Solution:
3NF: Relation is said to be in 3NF if:
1) It is in 2NF.
2) Remove transitive dependency.
• It is not in 3NF.
4. Normalization Example (Ex.1): Solution
23
1) 1NF: make each attribute is represented by atomic value.
4. Normalization Example (Ex.1): Solution
Client_no CName PropertyNo Address rent_start rent_end rent ownerNo oName
CR76
CR76
John kay
John kay
PG4
PG16
6 st.G
5 Novar
1-Jul-00
1-Sep-02
31-Aug-01
1-Sep-02
350
450
C040
C093
Tina
Tony
CR56
CR56
CR56
Aline Set
Aline Set
Aline Set
PG4
PG36
PG16
6 st.G
2 Manor
5 Novar
1-Sep-99
10-oct-00
1-Nov-02
10-Jun-00
1-Dec-01
1-Aug-03
350
370
450
C040
C093
C093
Tina
Tony
Tony
24
Choose Client_no + PropertyNo  composite primary key
4. Normalization Example (Ex.1): Solution
Client_no PropertyNo CName Address rent_start rent_end rent ownerNo oName
CR76
CR76
PG4
PG16
John kay
John kay
6 st.G
5 Novar
1-Jul-00
1-Sep-02
31-Aug-01
1-Sep-02
350
450
C040
C093
Tina
Tony
CR56
CR56
CR56
PG4
PG36
PG16
Aline Set
Aline Set
Aline Set
6 st.G
2 Manor
5 Novar
1-Sep-99
10-oct-00
1-Nov-02
10-Jun-00
1-Dec-01
1-Aug-03
350
370
450
C040
C093
C093
Tina
Tony
Tony
25
2) 2NF: remove partial dependency
Client_no  CName
PropertyNo  Address, rent, ownerNo, oName
4. Normalization Example (Ex.1): Solution
Client_no PropertyNo rent_start rent_end
CR76
CR76
PG4
PG16
1-Jul-00
1-Sep-02
31-Aug-01
1-Sep-02
CR56
CR56
CR56
PG4
PG36
PG16
1-Sep-99
10-oct-00
1-Nov-02
10-Jun-00
1-Dec-01
1-Aug-03
Client_no CName
CR76 John kay
CR56 Aline Set
26
3) 3NF: remove transitive dependency
ownerNo  oName
4. Normalization Example (Ex.1): Solution
Client_no PropertyNo rent_start rent_end
CR76
CR76
PG4
PG16
1-Jul-00
1-Sep-02
31-Aug-01
1-Sep-02
CR56
CR56
CR56
PG4
PG36
PG16
1-Sep-99
10-oct-00
1-Nov-02
10-Jun-00
1-Dec-01
1-Aug-03
Client_no CName
CR76 John kay
CR56 Aline Set
PropertyNo Address rent ownerNo
PG4 6 st.G 350 C040
PG16 5 Novar 450 C093
PG36 2 Manor 370 C093
ownerNo oName
C040 Tina
C093 Tony
27
• Apply the various normalization steps to convert the following table into a
normal form.
4. Normalization Example (Ex.2)
Invoice
No.
Date
Cust.
No.
Cust.
Name
Cust.
Address
Cust.
City
Cust.
State
ItemID
Item
Description
Item.Q
ty
Item
Price
Item
Total
Order
total
price
125 9/13/2002 56 Foo, Inc.
23 Main
St,thorpleb
urg
thorpleb
urg
TX 563 56"Blue Fre 4 3.50 $ 14.00 $ 82.00 $
851 Spline End I 32 0.25 $ 8.00 $ 82.00 $
652 3' Red Fre 5 12.00 $ 60.00 $ 82.00 $
126 9/14/2002 2
Freens R
Us
1600
Pennsylva
nia
Washing
ton
DC 563 56"Blue Fre 500 3.50 $
1750.00
$
10750.0
0 $
652 3' Red Fre 750 12.00 $
9000.00
$
10750.0
0 $
28
Solution:
• To be in 1NF
1) 1NF: make each attribute is represented by atomic value.
4. Normalization Example (Ex.2): Solution
Invoic
e No.
Date
Cust.No
.
Cust. Name
Cust.
Address
Cust. City
Cust.
State
ItemID
Item
Description
Item.Qt
y
Item Price Item Total
Order
total price
125 9/13/2002 56 Foo, Inc.
23 Main
St,thorplebur
g
thorplebur
g
TX 563 56"Blue Fre 4 3.50 $ 14.00 $ 82.00 $
125 9/13/2002 56 Foo, Inc.
23 Main
St,thorplebur
g
thorplebur
g
TX 851 Spline End I 32 0.25 $ 8.00 $ 82.00 $
125 9/13/2002 56 Foo, Inc.
23 Main
St,thorplebur
g
thorplebur
g
TX 652 3' Red Fre 5 12.00 $ 60.00 $ 82.00 $
126 9/14/2002 2
Freens R
Us
1600
Pennsylvani
a
Washingto
n
DC 563 56"Blue Fre 500 3.50 $ 1750.00 $
10750.00
$
126 9/14/2002 2
Freens R
Us
1600
Pennsylvani
a
Washingto
n
DC 652 3' Red Fre 750 12.00 $ 9000.00 $
10750.00
$
29
Choose Invoice No. + ItemID  composite primary key
4. Normalization Example (Ex.2): Solution
Invoice
No.
ItemID Date Cust.No. Cust. Name Cust. Address Cust. City
Cust.
State
Item
Description
Item.Qt
y
Item
Price
Item
Total
Order total price
125 563 9/13/2002 56 Foo, Inc.
23 Main
St,thorplebur
g
thorplebu
rg
TX 56"Blue Fre 4 3.50 $ 14.00 $ 82.00 $
125 851 9/13/2002 56 Foo, Inc.
23 Main
St,thorplebur
g
thorplebu
rg
TX Spline End I 32 0.25 $ 8.00 $ 82.00 $
125 652 9/13/2002 56 Foo, Inc.
23 Main
St,thorplebur
g
thorplebu
rg
TX 3' Red Fre 5 12.00 $ 60.00 $ 82.00 $
126 563 9/14/2002 2
Freens R
Us
1600
Pennsylvania
Washingt
on
DC 56"Blue Fre 500 3.50 $
1750.0
0 $
10750.00 $
126 652 9/14/2002 2
Freens R
Us
1600
Pennsylvania
Washingt
on
DC 3' Red Fre 750 12.00 $
9000.0
0 $
10750.00 $
30
2) 2NF: remove partial dependency
Invoice No.  Date, Cust.No., Cust. Name, Cust. Address, Cust. City, Cust. State, Order
total price
ItemID  Item Description, Item Price
Invoice No. + ItemID  Item.Qty, Item Total
4. Normalization Example (Ex.2): Solution
Invoice No. ItemID Item.Qty Item Total
125 563 4 14.00 $
125 851 32 8.00 $
125 652 5 60.00 $
126 563 500 1750.00 $
126 652 750 9000.00 $
Invoice
No.
Date
Cust.N
o.
Cust.
Name
Cust.
Address
Cust.
City
Cust.
State
Order total
price
125 9/13/2002 56
Foo,
Inc.
23 Main
St,thorple
burg
thorple
burg
TX 82.00 $
126 9/14/2002 2
Freens
R Us
1600
Pennsylv
ania
Washi
ngton
DC 10750.00 $
ItemID Item Description Item Price
563 56"Blue Fre 3.50 $
851 Spline End I 0.25 $
652 3' Red Fre 12.00 $
31
3) 3NF: Tables are in 3 NF as there is no transitive dependency
4. Normalization Example (Ex.2): Solution
Thanks for your attention!

Chapter+3+-+Normalization.pdf

  • 1.
  • 2.
    Chapter 3 Content: 1.Why Normalize? 2. Normalization 3. Dependencies 4. Normalization Example 2 Chapter 3: Normalization
  • 3.
    1. Why Normalize? •If your database is not normalized, it can be inaccurate, slow, inefficient. • It might not produce the data you expect, or want (update and delete anomalies). • It makes creating queries, forms, and reports are much easier to design.
  • 4.
    4 • Normalization: sequenceof steps by which RDB is both created and improved. Advantages of Normalization: 1. Get relations in more desirable form. 2. Make database more accurate and efficient. 3. Make creating queries easier. 4. Remove duplication. 2. Normalization
  • 5.
    5 • Normalization: sequenceof steps by which RDB is both created and improved. 2. Normalization (Normalization Flow)
  • 6.
    • A relationis said to be in first normal form if the data is held in a two- dimensional table with each attribute represented by an atomic value. • The intersection of a row and a column must contain an indivisible value. • Each row and column position in the table there exists one value, never a set of values. • All attributes are atomic - any single attribute must not be composed of multiple attributes. 6 First Normal Form (1NF)
  • 7.
    The data wewould want to store could be expressed as: Project No Project Name Employee No Employee Name Rate category Rate 1203 Madagascar travel site 11 Jessica Brookes A £90 12 Andy Evans B £80 16 Max Fat C £70 1506 Online estate agency 11 Jessica Brookes A £90 17 Alex Branton B £80 7 First Normal Form (1NF)
  • 8.
    • The intersectionof a row and a column must contain an indivisible value Project No. Project Name Employee No. Employee Name Rate category Rate 1203 Madagascar travel site 11 Jessica Brookes A £90 1203 Madagascar travel site 12 Andy Evans B £80 1203 Madagascat travel site 16 Max Fat C £70 1506 Online estate agency 11 Jessica Brookes A £90 1506 Online estate agency 17 Alex Branton B £70 8 Project No. Project Name Employee No. Solution
  • 9.
    Three problems becomeapparent with our current model: Tables in a RDBMS use a simple grid structure • All tables in an RDBMS need a key • Data entry should be kept to a minimum • Redundant data 9 First Normal Form (1NF)
  • 10.
    10 1NF: • Relation issaid to be in 1NF if data is held in a table with each attribute is represented by atomic value. 2NF: • Relation is said to be in 2NF if: 1) It is in 1NF. 2) Remove partial dependency. Normalization (Normalization Flow)
  • 11.
    11 3NF: • Relation issaid to be in 3NF if: 1) It is in 2NF. 2) Remove transitive dependency. Normalization (Normalization Flow)
  • 12.
    12 Partial dependency: whennon-key attribute is determined by a part, but not all composite P.K. Transitive dependency: when non-key attribute determines another non-key attribute. 3. Dependencies
  • 13.
    • A relationis said to be in second normal form if the relation (1) is in 1NF and (2) all attributes that are not part of the primary key are completely functionally dependent on the primary key. (Partial dependencies must be removed) • Second Normal Form (2NF) the relation must be in 1NF and each non key attribute must be fully dependent on the whole key (not a subset of the key). 13 Second normal form 2NF
  • 14.
    Third normal form3NF • A relation is said to be in 3NF if it (1) is in 2NF and (2) no attributes that are not part of the primary key are transitively dependent on the primary key. • The key then to move 2NF relations into 3NF is removing any transitive dependencies that may exist in the relations. 14
  • 15.
    Dependencies: Definitions • PartialDependency – when an non-key attribute is determined by a part, but not the whole, of a COMPOSITE primary key. 15 CUSTOMER Cust_ID Name Order_ID 101 AT&T 1234 101 AT&T 156 125 Cisco 1250 Partial Dependency
  • 16.
    • Transitive Dependency– when a non-key attribute determines another non-key attribute. 16 EMPLOYEE Emp_ID F_Name L_Name Dept_ID Dept_Name 111 Mary Jones 1 Acct 122 Sarah Smith 2 Mktg Transitive Dependency Dependencies: Definitions
  • 17.
    Example 1 17 • Isthe table in the 0NF
  • 18.
  • 19.
  • 20.
    3 NF 20 . Service Place ServiceType Service Date . 12/2002 3/2000 11/99 Service Type Service Place Service Type Transitive Dependency
  • 21.
    21 • What ismeant by third normal form (3NF)? Examine the following table to check if it is in 3NF. If yes, explain your answer. Otherwise convert the table into 3NF. 4. Normalization Example Client_no CName PropertyNo Address rent_start rent_end rent ownerNo oName CR76 John kay PG4 PG16 6 st.G 5 Novar 1-Jul-00 1-Sep-02 31-Aug-01 1-Sep-02 350 450 C040 C093 Tina Tony CR56 Aline Set PG4 PG36 PG16 6 st.G 2 Manor 5 Novar 1-Sep-99 10-oct-00 1-Nov-02 10-Jun-00 1-Dec-01 1-Aug-03 350 370 450 C040 C093 C093 Tina Tony Tony
  • 22.
    22 Solution: 3NF: Relation issaid to be in 3NF if: 1) It is in 2NF. 2) Remove transitive dependency. • It is not in 3NF. 4. Normalization Example (Ex.1): Solution
  • 23.
    23 1) 1NF: makeeach attribute is represented by atomic value. 4. Normalization Example (Ex.1): Solution Client_no CName PropertyNo Address rent_start rent_end rent ownerNo oName CR76 CR76 John kay John kay PG4 PG16 6 st.G 5 Novar 1-Jul-00 1-Sep-02 31-Aug-01 1-Sep-02 350 450 C040 C093 Tina Tony CR56 CR56 CR56 Aline Set Aline Set Aline Set PG4 PG36 PG16 6 st.G 2 Manor 5 Novar 1-Sep-99 10-oct-00 1-Nov-02 10-Jun-00 1-Dec-01 1-Aug-03 350 370 450 C040 C093 C093 Tina Tony Tony
  • 24.
    24 Choose Client_no +PropertyNo  composite primary key 4. Normalization Example (Ex.1): Solution Client_no PropertyNo CName Address rent_start rent_end rent ownerNo oName CR76 CR76 PG4 PG16 John kay John kay 6 st.G 5 Novar 1-Jul-00 1-Sep-02 31-Aug-01 1-Sep-02 350 450 C040 C093 Tina Tony CR56 CR56 CR56 PG4 PG36 PG16 Aline Set Aline Set Aline Set 6 st.G 2 Manor 5 Novar 1-Sep-99 10-oct-00 1-Nov-02 10-Jun-00 1-Dec-01 1-Aug-03 350 370 450 C040 C093 C093 Tina Tony Tony
  • 25.
    25 2) 2NF: removepartial dependency Client_no  CName PropertyNo  Address, rent, ownerNo, oName 4. Normalization Example (Ex.1): Solution Client_no PropertyNo rent_start rent_end CR76 CR76 PG4 PG16 1-Jul-00 1-Sep-02 31-Aug-01 1-Sep-02 CR56 CR56 CR56 PG4 PG36 PG16 1-Sep-99 10-oct-00 1-Nov-02 10-Jun-00 1-Dec-01 1-Aug-03 Client_no CName CR76 John kay CR56 Aline Set
  • 26.
    26 3) 3NF: removetransitive dependency ownerNo  oName 4. Normalization Example (Ex.1): Solution Client_no PropertyNo rent_start rent_end CR76 CR76 PG4 PG16 1-Jul-00 1-Sep-02 31-Aug-01 1-Sep-02 CR56 CR56 CR56 PG4 PG36 PG16 1-Sep-99 10-oct-00 1-Nov-02 10-Jun-00 1-Dec-01 1-Aug-03 Client_no CName CR76 John kay CR56 Aline Set PropertyNo Address rent ownerNo PG4 6 st.G 350 C040 PG16 5 Novar 450 C093 PG36 2 Manor 370 C093 ownerNo oName C040 Tina C093 Tony
  • 27.
    27 • Apply thevarious normalization steps to convert the following table into a normal form. 4. Normalization Example (Ex.2) Invoice No. Date Cust. No. Cust. Name Cust. Address Cust. City Cust. State ItemID Item Description Item.Q ty Item Price Item Total Order total price 125 9/13/2002 56 Foo, Inc. 23 Main St,thorpleb urg thorpleb urg TX 563 56"Blue Fre 4 3.50 $ 14.00 $ 82.00 $ 851 Spline End I 32 0.25 $ 8.00 $ 82.00 $ 652 3' Red Fre 5 12.00 $ 60.00 $ 82.00 $ 126 9/14/2002 2 Freens R Us 1600 Pennsylva nia Washing ton DC 563 56"Blue Fre 500 3.50 $ 1750.00 $ 10750.0 0 $ 652 3' Red Fre 750 12.00 $ 9000.00 $ 10750.0 0 $
  • 28.
    28 Solution: • To bein 1NF 1) 1NF: make each attribute is represented by atomic value. 4. Normalization Example (Ex.2): Solution Invoic e No. Date Cust.No . Cust. Name Cust. Address Cust. City Cust. State ItemID Item Description Item.Qt y Item Price Item Total Order total price 125 9/13/2002 56 Foo, Inc. 23 Main St,thorplebur g thorplebur g TX 563 56"Blue Fre 4 3.50 $ 14.00 $ 82.00 $ 125 9/13/2002 56 Foo, Inc. 23 Main St,thorplebur g thorplebur g TX 851 Spline End I 32 0.25 $ 8.00 $ 82.00 $ 125 9/13/2002 56 Foo, Inc. 23 Main St,thorplebur g thorplebur g TX 652 3' Red Fre 5 12.00 $ 60.00 $ 82.00 $ 126 9/14/2002 2 Freens R Us 1600 Pennsylvani a Washingto n DC 563 56"Blue Fre 500 3.50 $ 1750.00 $ 10750.00 $ 126 9/14/2002 2 Freens R Us 1600 Pennsylvani a Washingto n DC 652 3' Red Fre 750 12.00 $ 9000.00 $ 10750.00 $
  • 29.
    29 Choose Invoice No.+ ItemID  composite primary key 4. Normalization Example (Ex.2): Solution Invoice No. ItemID Date Cust.No. Cust. Name Cust. Address Cust. City Cust. State Item Description Item.Qt y Item Price Item Total Order total price 125 563 9/13/2002 56 Foo, Inc. 23 Main St,thorplebur g thorplebu rg TX 56"Blue Fre 4 3.50 $ 14.00 $ 82.00 $ 125 851 9/13/2002 56 Foo, Inc. 23 Main St,thorplebur g thorplebu rg TX Spline End I 32 0.25 $ 8.00 $ 82.00 $ 125 652 9/13/2002 56 Foo, Inc. 23 Main St,thorplebur g thorplebu rg TX 3' Red Fre 5 12.00 $ 60.00 $ 82.00 $ 126 563 9/14/2002 2 Freens R Us 1600 Pennsylvania Washingt on DC 56"Blue Fre 500 3.50 $ 1750.0 0 $ 10750.00 $ 126 652 9/14/2002 2 Freens R Us 1600 Pennsylvania Washingt on DC 3' Red Fre 750 12.00 $ 9000.0 0 $ 10750.00 $
  • 30.
    30 2) 2NF: removepartial dependency Invoice No.  Date, Cust.No., Cust. Name, Cust. Address, Cust. City, Cust. State, Order total price ItemID  Item Description, Item Price Invoice No. + ItemID  Item.Qty, Item Total 4. Normalization Example (Ex.2): Solution Invoice No. ItemID Item.Qty Item Total 125 563 4 14.00 $ 125 851 32 8.00 $ 125 652 5 60.00 $ 126 563 500 1750.00 $ 126 652 750 9000.00 $ Invoice No. Date Cust.N o. Cust. Name Cust. Address Cust. City Cust. State Order total price 125 9/13/2002 56 Foo, Inc. 23 Main St,thorple burg thorple burg TX 82.00 $ 126 9/14/2002 2 Freens R Us 1600 Pennsylv ania Washi ngton DC 10750.00 $ ItemID Item Description Item Price 563 56"Blue Fre 3.50 $ 851 Spline End I 0.25 $ 652 3' Red Fre 12.00 $
  • 31.
    31 3) 3NF: Tablesare in 3 NF as there is no transitive dependency 4. Normalization Example (Ex.2): Solution
  • 32.
    Thanks for yourattention!