database normalisation by d.lukachuk
TRANSCRIPT
![Page 1: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/1.jpg)
Database Normalization
Principals of Database Normalization
by Dmytro Lukachuk
![Page 2: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/2.jpg)
Overview
• Normalization, main ideas;
• Normal forms;
• Normalization and Denormalization;
• Practical examples.
![Page 3: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/3.jpg)
Normalization
• Normalization is the process of organizing the attributes and tables to minimize redundancy.
Wikipedia
![Page 4: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/4.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/5.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/6.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/7.jpg)
Normal Form
• A set of requirements (rules, principals) that satisfy relations in DB.
![Page 8: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/9.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/10.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/11.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/12.jpg)
Employee -> DepartmentDepartment -> TelephoneEmployee -> Telephone (transitive dependency)
![Page 13: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/14.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/15.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/16.jpg)
Disadvantages of Normalization
• Joins
• Bad indexing strategy
![Page 17: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/17.jpg)
Advantages of Denormalization
• No joins
• Fast select
• Efficient index usage
![Page 18: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/18.jpg)
Disadvantages of Denormalization
• Costly inserts
• Costly updates
![Page 19: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/19.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/20.jpg)
Slider structure analysis:Slider table
![Page 21: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/21.jpg)
Slider_config table
![Page 22: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/22.jpg)
Slider_config_scope
![Page 23: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/23.jpg)
Slide table
![Page 24: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/24.jpg)
Slide_config table
![Page 25: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/25.jpg)
Controversial aspects
![Page 26: Database normalisation by D.Lukachuk](https://reader033.vdocuments.net/reader033/viewer/2022042607/55ab61251a28ab602f8b46e8/html5/thumbnails/26.jpg)
What is the best way?
The best way is to –MIX principals of normalization with denormalization approach depending on certain application purposes.