Coding Bootcamp: Database Normalization

Database Normalization

Background and terminology

Relational Database Management System (RDBMS)

Primary and Foreign Key Fields

Relational database model

Database anomalies

Database anomalies

What is Normalization

Problem without normalization

Insertion anomaly

Modification anomaly

Deletion anomaly

Normalization overview

1st Normal Form

First normal form: An attribute (column) of a table cannot hold multiple values. It should hold only atomic values

1st normal form

1st normal form

1st normal form – select failure


SELECT *
FROM employee
WHERE language = ‘English’

Potential solution:
SELECT *
FROM employee
WHERE language LIKE ‘%English%’

1st normal form – update failure


What happens if we want to add ‘English’ language to George?

We need to know that he already speaks French:
UPDATE employee
SET language = ‘French, English’
WHERE name = ‘George’

1st normal form – An alternative approach

1st normal form – New problems

1st normal form

1st normal form

1st normal form

1st normal form – In a nutshell

1st normal form – In a nutshell

Functional Dependencies

Functional dependencies – example 1

Examples of functional dependencies:

Functional dependencies – example 2


We say an attribute B has a functional dependency on another attribute A, if for any two records, which have the same value for A, then the values for B in these two records must be the same

Functional dependencies – example 3


Knowing the Team name we can identify uniquely the League it participates

Functional dependencies – example 4

Functional dependencies

2nd Normal Form

Second normal form: an entity type is in second normal form (2NF) when it is in 1NF and when every non-key attribute, any attribute that is not part of the primary key, is fully dependent on the primary key

2nd Normal Form – example 1


2NF: No non-prime attribute is dependent on the proper subset of any candidate key of the table

2nd Normal Form – example 1

2nd normal form – Approach

2nd normal form – Example 1

2nd normal form – Example 2


{Manufacturer, Model} → Manufacturer Country

2nd normal form – Example 2

2nd normal form – In a nutshell

2nd normal form – In a nutshell

3rd Normal Form

Third normal form: an entity type is in third normal form (3NF) when it is in 2NF and all non-primary fields are dependent on the primary key

3rd Normal Form

3rd Normal Form

3rd Normal Form

3rd Normal Form

3rd normal form – In a nutshell

3rd Normal Form

Some good reasons not to normalize

Exercises

Exercise 1

a) A → B

b) B → C

c) BC → A

d) AC → B

Exercise 2

Exercise 3

Exercise 4

Exercise 5

Exercise 6


Creative Commons Licence
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.