Database Normalization
Principals of Database Normalization
by Dmytro Lukachuk
Overview
• Normalization, main ideas;
• Normal forms;
• Normalization and Denormalization;
• Practical examples.
Normalization
• Normalization is the process of organizing the attributes and tables to minimize redundancy.
Wikipedia
Aims of normalization:
• Minimize logical redundancy;
• Free the DB of modification anomalies;
• Minimize redesign when extending DB structure;
• Simplification for applying integrity constraints.
Edgar Frank Codd
Other suggestions:
• The aim of Normalization is not to decrease or increase performance;
• The aim of Normalization is not to decrease or increase physical memory size of DB.
So what is Normalization?
• The process of transformation of database relations to the structure that fits normal form (NF).
Normal Form
• A set of requirements (rules, principals) that satisfy relations in DB.
Normal forms:
• 1st Normal Form (1NF);
• 2nd Normal Form (1NF);
• 3rd Normal Form (3NF);
• Boyce-Codd Normal Form (BCNF);
• 4th Normal Form (4NF);
• 5th Normal Form (5NF);
• Domain/key Normal Form (DKNF);
• 6th Normal Form (6NF).
1st Normal Form Principals
• No top-to-bottom ordering to the rows;
• No left-to-right ordering to the columns;
• No duplicate rows;
• Every cell contains only one value;
• All columns are regular (no hidden components).
2nd Normal Form Principals
• Relations are in 1st Normal Form;
• Every non-prime attribute is dependent on candidate key.
3rd Normal Form
• Relations are in 2nd Normal Form;
• Non-prime attribute can be determined only by the candidate key and not any other non-prime attribute (transitive dependency).
Employee -> DepartmentDepartment -> TelephoneEmployee -> Telephone (transitive dependency)
Boyce-Codd Normal Form
• Relations are in 3rd Normal Form
• Primary key does not depend on non-prime attribute.
Relation is in 3NF but not in BCNF when relation has two or more candidate key that are composite and have common attribute
Denormalization
• Transformation of DB structure to the form that does not satisfy normal forms.
• Process of optimizing performance by adding redundant data or by grouping data.
Advantages of Normalization
• Smaller
• Fast updates
• Fast inserts
• Less need for heavy group by or distinct queries as data is not duplicated
Disadvantages of Normalization
• Joins
• Bad indexing strategy
Advantages of Denormalization
• No joins
• Fast select
• Efficient index usage
Disadvantages of Denormalization
• Costly inserts
• Costly updates
Compare
Normalization:SELECT product_name, order_date
FROM orders
INNER JOIN products USING(product_id)
WHERE product_name like 'A%'
ORDER by order_date DESC
Denormalizaion:SELECT product_name, order_date
FROM orders
WHERE product_name like 'A%'
ORDER by order_date DESC
Slider structure analysis:Slider table
Slider_config table
Slider_config_scope
Slide table
Slide_config table
Controversial aspects
What is the best way?
The best way is to –MIX principals of normalization with denormalization approach depending on certain application purposes.
Top Related