c2 Normalization
c2 Normalization
Normalization
• Normalization Purpose
• Redundancy and Data Anomalies
• 1FN: First Normal Form
• 2FN: Second Normal Form
• 3FN: Thrird Normal Form
• Examples
Normalization
Normalization is the process of efficiently
organizing data in a database with two goals in
mind
First goal: to eliminate redundant data
– for example, don’t storing the same data in
more than one table
Second Goal: to ensure data dependencies make
sense
– for example, only storing related data in a
table
2010/2011 Topic #2: Normalization (Relational Database Design) 2
1
20/12/2010
Normalization Purpose
• To avoid redundancy by storing each ‘fact’ within the
database only once.
• To put data into a form that conforms to relational
principles (e.g., single valued attributes, each relation
represents one entity)
• To put the data into a form that is more able to accurately
accommodate change
• To facilitate the enforcement of data constraints.
• To avoid ‘anomalies’.
2
20/12/2010
Example: We have the following relation that contains staff and department details:
3
20/12/2010
4
20/12/2010
Summary
Steps in the Normalization process (up to 3NF):
1. Relation must have a fixed number of atomic
attributes.
2. Identify primary key.
3. Check that all attributes (except primary key
members) depend on the WHOLE primary key
(not a part).
4. If partial dependency ((3) is not true) break the
relation.
5. Check that the attributes don’t depend on
another attribute, which is not the primary key.
6. If transitive dependency ((5) is not true) break the
relation.
2010/2011 Topic #2: Normalization (Relational Database Design) 10
5
20/12/2010
1. Remove the outermost repeating group (and any nested repeated groups it may
contain) and create a new relation to contain it. (rename original to indicate 1NF)
ORDER-1 (order-no, order-date, cust-no, cust-name, cust-add, order-total
(prod-no, prod-desc, unit-price, ord-qty, line-total)
2. Add to this relation a copy of the PK of the relation immediately enclosing it.
ORDER-1 (order-no, order-date, cust-no, cust-name, cust-add, order-total
(order-no, prod-no, prod-desc, unit-price, ord-qty, line-total)
3. Name the new entity (appending the number 1 to indicate 1NF)
ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total)
4. Determine the PK of the new entity
ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total)
2010/2011 Topic #2: Normalization
13 (Relational Database Design)
6
20/12/2010
(prod-desc, unit-price)
2. Add to this relation a copy of the attribute(s) which determines these offending
attributes. These will automatically become the primary key of this new relation..
ORDER-LINE-1 (order-no, prod-no, ord-qty, line-total)
(prod-no, prod-desc, unit-price)
3. Name the new entity (appending the number 2 to indicate 2NF)
PRODUCT-2 (prod-no, prod-desc, unit-price)
4. Rename the original entity (ending with a 2 to indicate 2NF)
ORDER-LINE-2 (order-no, prod-no, ord-qty,
2010/2011 Topic #2: Normalization
line-total)
15 (Relational Database Design)
7
20/12/2010
(cust-name, cust-add )
2. Add to this relation a copy of the attribute(s) which determines these offending
attributes. These will automatically become the primary key of this new relation..
ORDER-2 (order-no, order-date, cust-no, order-total
8
20/12/2010
order-no prod-no
ORDER PRODUCT
Normalize: (1)
• holiday(place_id, place_name, client_id, client_name, date)
• Atomic Attributes?
– Yes, it is 1FN
• 2FN – All attributes (except those belonging to the primary key) depend on the
whole primary key?
– place_name depends on place_id
– create: place_2(place_id, place_name)
– client_name depends on client_id
– create: client_2 (client_id, client_name)
– and holiday_2 (place_id, client_id, date)
• Transitive Dependences?
– No transitive dependences 3FN
9
20/12/2010
Normalize: (2)
• book(room_id,date,client_id,client_name)
• Atomic Attributes?
– Yes, it is 1FN
• Transitive Dependences?
– No transitive dependences 3FN
10