Normalization Assignment
Normalization Assignment
Roll no: 12
Normalization
Example 2 - inventory:
part # warehouse # wh_address quantity
100 05 Mpls 200
100 08 StPaul 300
200 05 Mpls 250
200 10 Madison 400
300 08 StPaul 350
Update Anomalies:
UPDATE
address of warehouse stored in many rows
if address changes, must change all rows
DELETE
if the last row for a warehouse is deleted, the address is lost
INSERT
to insert a new row, warehouse address must be known
The problem occurs because this table is not focused on one primary key - it is “about” two things -
warehouses and parts in warehouses.
Solution to Multiple Focus Problems
A relation that is in 1NF but not in a higher normal form has a composite key (more than one attribute in
the key)
Example 2 - inventory:
One table about warehouses:
warehouse# wh_address
05 Mpls
08 StPaul
10 Madison
One table about inventory with a composite key:
part# warehouse# Quantity
100 05 200
100 08 300
200 05 250
200 10 400
300 08 350
1NF + every non-key attribute is fully functionally dependent on the primary key
Example 3 - departments:
Name Dept dept_loc
Smith 402 100
Jones 401 200
King 402 100
Turner 400 200
Olson 401 200
Update Anomalies:
UPDATE - location appears many times - if location of a department changes, must fetch and
change all rows containing that location
DELETE - if the last row for a department is deleted, the department location information is lost
2NF + every non-key attribute is non-transitively functionally dependent on the primary key
OR
OR
(Kent) Each attribute in the relation is functionally dependent on the key, the whole key, and nothing but
the key
Example 4 - locations:
dept# dept_name dept_loc
400 Programming 200
401 Financial 200
402 Academic 100
403 Support 300
Example 5 - stock:
s# sname p# qty
10 GE 102 1000
10 GE 103 625
10 GE 104 2000
20 TRW 102 500
20 TRW 105 1200
30 Syl 103 1300
technically in 3NF
qty is the only non-key attribute (like example 1)
candidate keys are (s#, p#) and (sname, p#)
didn't require components of an alternate key to be fully functionally dependent on the
primary key
Problems with 3NF Relations
The problems associated with alternate key components were not recognized in the early formulations of
the relational model.
Because of this problem, 3NF (as we have described it) is sometimes referred to as “early 3rd Normal
Form”
SECOND EXAMPLE OF NORMALIZATION:
As per the rule of first normal form, an attribute (column) of a table cannot hold multiple values. It should
hold only atomic values.
Example: Suppose a company wants to store the names and contact details of its employees. It creates a
table that looks like this:
8812121212
102 Jon Kanpur
9900012222
9990000123
104 Lester Bangalore
8123450987
Two employees (Jon & Lester) are having two mobile numbers so the company stored them in the same
field as you can see in the table above.
This table is not in 1NF as the rule says “each attribute of a table must have atomic (single) values”, the
emp_mobile values for employees Jon & Lester violates that rule.
To make the table complies with 1NF we should have the data like this:
No non-prime attribute is dependent on the proper subset of any candidate key of table.
An attribute that is not part of any candidate key is known as non-prime attribute.
Example: Suppose a school wants to store the data of teachers and the subjects they teach. They create a
table that looks like this: Since a teacher can teach more than one subjects, the table can have multiple
rows for a same teacher.
111 Maths 38
111 Physics 38
222 Biology 38
333 Physics 40
333 Chemistry 40
The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF because non
prime attribute teacher_age is dependent on teacher_id alone which is a proper subset of candidate key.
This violates the rule for 2NF as the rule says “no non-prime attribute is dependent on the proper subset
of any candidate key of the table”.
To make the table complies with 2NF we can break it in two tables like this:
teacher_details table:
teacher_id teacher_age
111 38
222 38
333 40
teacher_subject table:
teacher_id Subject
111 Maths
111 Physics
222 Biology
333 Physics
333 Chemistry
Transitive functional dependency of non-prime attribute on any super key should be removed.
An attribute that is not part of any candidate key is known as non-prime attribute.
In other words 3NF can be explained like this: A table is in 3NF if it is in 2NF and for each functional
dependency X-> Y at least one of the following conditions hold:
An attribute that is a part of one of the candidate keys is known as prime attribute.
Example: Suppose a company wants to store the complete address of each employee, they create a table
named employee_details that looks like this:
Here, emp_state, emp_city & emp_district dependent on emp_zip. And, emp_zip is dependent on emp_id
that makes non-prime attributes (emp_state, emp_city & emp_district) transitively dependent on super
key (emp_id). This violates the rule of 3NF.
To make this table complies with 3NF we have to break the table into two tables to remove the transitive
dependency:
employee table:
employee_zip table: