26
Database Normalization Principals of Database Normalization by Dmytro Lukachuk

Database normalisation by D.Lukachuk

Embed Size (px)

Citation preview

Page 1: Database normalisation by D.Lukachuk

Database Normalization

Principals of Database Normalization

by Dmytro Lukachuk

Page 2: Database normalisation by D.Lukachuk

Overview

• Normalization, main ideas;

• Normal forms;

• Normalization and Denormalization;

• Practical examples.

Page 3: Database normalisation by D.Lukachuk

Normalization

• Normalization is the process of organizing the attributes and tables to minimize redundancy.

Wikipedia

Page 4: Database normalisation by D.Lukachuk

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

Page 5: Database normalisation by D.Lukachuk

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.

Page 6: Database normalisation by D.Lukachuk

So what is Normalization?

• The process of transformation of database relations to the structure that fits normal form (NF).

Page 7: Database normalisation by D.Lukachuk

Normal Form

• A set of requirements (rules, principals) that satisfy relations in DB.

Page 8: Database normalisation by D.Lukachuk

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).

Page 9: Database normalisation by D.Lukachuk

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).

Page 10: Database normalisation by D.Lukachuk

2nd Normal Form Principals

• Relations are in 1st Normal Form;

• Every non-prime attribute is dependent on candidate key.

Page 11: Database normalisation by D.Lukachuk

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).

Page 12: Database normalisation by D.Lukachuk

Employee -> DepartmentDepartment -> TelephoneEmployee -> Telephone (transitive dependency)

Page 13: Database normalisation by D.Lukachuk

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

Page 14: Database normalisation by D.Lukachuk

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.

Page 15: Database normalisation by D.Lukachuk

Advantages of Normalization

• Smaller

• Fast updates

• Fast inserts

• Less need for heavy group by or distinct queries as data is not duplicated

Page 16: Database normalisation by D.Lukachuk

Disadvantages of Normalization

• Joins

• Bad indexing strategy

Page 17: Database normalisation by D.Lukachuk

Advantages of Denormalization

• No joins

• Fast select

• Efficient index usage

Page 18: Database normalisation by D.Lukachuk

Disadvantages of Denormalization

• Costly inserts

• Costly updates

Page 19: Database normalisation by D.Lukachuk

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

Page 20: Database normalisation by D.Lukachuk

Slider structure analysis:Slider table

Page 21: Database normalisation by D.Lukachuk

Slider_config table

Page 22: Database normalisation by D.Lukachuk

Slider_config_scope

Page 23: Database normalisation by D.Lukachuk

Slide table

Page 24: Database normalisation by D.Lukachuk

Slide_config table

Page 25: Database normalisation by D.Lukachuk

Controversial aspects

Page 26: Database normalisation by D.Lukachuk

What is the best way?

The best way is to –MIX principals of normalization with denormalization approach depending on certain application purposes.