Carl Carison
Carl Carison
Normalization in Databases
A B C A B B C
1 A 1 1 A
2 B 2 2 B
r A,B(r) B,C(r)
A B C
A (r) B (r)
1 A
2 B
Normal Forms
1NF
2NF
3NF
Other…
Not covered.
Normal Forms: Review
PART
WAREHOUSE A WAREHOUSE B WAREHOUSE C
(Primary Key)
PART WAREHOUSE
(Primary Key) (Primary Key) QUANTITY
P0010 Warehouse A 400
PART_STOCK TABLE
PART (Primary Key) WAREHOUSE (Primary Key) QUANTITY
P0010 Warehouse A 400
P0010 Warehouse B 543
P0010 Warehouse C 329
P0020 Warehouse B 200
P0020 Warehouse D 278
WAREHOUSE TABLE
1
∞
WAREHOUSE (Primary Key) WAREHOUSE_ADDRESS
Warehouse A 1608 New Field Road
Warehouse B 4141 Greenway Drive
Warehouse C 171 Pine Lane
Warehouse D 800 Massey Street
Third Normal Form – 3NF
Usually used in tables with a single- field
primary key
Records do not depend on anything other
than a table's primary key
Each non-key field is a fact about the key
Values in a record that are not part of that record's key
do not belong in the table. In general, any time the
contents of a group of fields may apply to more than a
single record in the table, consider placing those fields in
a separate table.
Table Violating 3NF
EMPLOYEE_DEPARTMENT TABLE
EMPNO
FIRSTNAME LASTNAME WORKDEPT DEPTNAME
(Primary Key)
DEPARTMENT TABLE
∞
1
E11 Operations
Adv-
Student# Advisor# AdvisorFName AdvisorLName Class#
Room
1022 10 Susan Jones 412 101-07
Adv-
Student# Advisor# AdvisorFName AdvisorLName Class#
Room
1022 10 Susan Jones 412 101-07
Adv-
Student# Advisor# AdvisorFName AdvisorLName Class#
Room
1022 10 Susan Jones 412 101-07
1022 10
• Advisor fields dependJones
Susan
on Student# 412 159-02
1022 143-01
4123 12 Anne Smith 216
1022 159-02
2011 10 Susan Jones 412
4123 201-01
4123 211-02
4123 214-01
Tables Registration in 2NF
Who about the Students?
Table: Registration
Table: Students
1022 143-01
4123 12 Anne Smith 216
1022 159-02
2011 10 Susan Jones 412
4123 201-01
4123 211-02
What is the candidate key for Students?
4123 214-01
Tables in 2NF.
Table: Advisors
1022 101-07
12 Anne Smith 216
1022 143-01
Table: Students
1022 159-02
Student# Advisor#
4123 201-01
2011 10
Relationships for Example 1
EmpID Name Dept Dept Name Proj 1 Time Proj 2 Time Proj 3 Time
Code Proj 1 Proj 2 Proj 3
EN1-26 Sean Breen TW Technical Writing 30-T3 25% 30-TC 40% 31-T3 30%
EN1-33 Amy Guya TW Technical Writing 30-T3 50% 30-TC 35% 31-T3 60%
Employees Departments
Employees_and_Projects
EmpID DeptCode
EmpID
FirstName
ProjectNumber DeptName
LastName
TimeonProject
DeptCode
Example 3
• Un-normalized Table:
EmpID FName LName Manager Dept Sector Spouse Child1 Child2 Child3
458 Homer Simpson Mr. Burns Safety 7G Marge Bart Lisa Maggie
Table in First Normal Form
No more repeated fields
EmpID Dependent
458 Marge
458 Bart
458 Lisa
458 Maggie
Tables in Second Normal Form
Removed Repeated Data From Table
Step 2
EmpID FName LName ManagerID Dept Sector
285 Carl Carlson 2 Engineering 6G
365 Lenny 2 Marketing 8G
458 Homer Simpson 1 Safety 7G
Dependents Table
Department Table
EmpID Dependent
DeptCode Department Sector ManagerID
458 Marge EN Engineering 6G 2
458 Bart MK Marketing 8G 2
458 Lisa SF Safety 7G 1
458 Maggie
Example 4
Table Violating 1st Normal Form
Rep ID Representative Client 1 Time 1 Client 2 Time 2 Client 3 Time 3
TS-89 Gilroy Gladstone US Corp. 14 hrs Taggarts 26 hrs Kilroy Inc. 9 hrs
RK-56 Mary Mayhem Italiana 67 hrs Linkers 2 hrs
Although this table is in 1NF it contains redundant data. For example, information about the supplier's location and the
location's status have to be repeated for every part supplied. Redundancy causes what are called update anomalies. Update
anomalies are problems that arise when information is inserted, deleted, or updated. For example, the following anomalies
could occur in this table:
INSERT. The fact that a certain supplier (s5) is located in a particular city (Athens) cannot be added until they supplied a part.
DELETE. If a row is deleted, then not only is the information about quantity and part lost but also information about the supplier.
UPDATE. If supplier s1 moved from London to New York, then two rows would have to be updated with this new information.
Tables in 2NF
Suppliers Parts
Tables in 2NF but not in 3NF still contain modification anomalies. In the example of Suppliers, they are:
INSERT. The fact that a particular city has a certain status (Rome has a status of 50) cannot be inserted until
there is a supplier in the city.
DELETE. Deleting any row in SUPPLIER destroys the status information about the city as well as the
association between supplier and city.