Normalization
Introduction to Database
By
Michael Kona
Normalization
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
Normalization
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
First Normal Form (1NF)
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
Process for 1NF
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
Example
The First normal form simply says that each cell of a table should contain exactly one value.
In the first row, we are storing 2 courses against Prof. George. This isn’t the optimal way
If we want to edit some information related to CS101, we do not have to touch the data corresponding to CS154. Also, observe that each row stores unique information.
Second Normal Form (2NF)
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
Example for 2NF
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
Example
Source url:-https://codeandwork.github.io/courses/cs/database_normalization.html
Third Normal Form (3NF)
To be in third normal form, the relation must be in second normal form.
Also all transitive dependencies must be removed;
a non-key attribute may not be functionally dependent on another non-key attribute.
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
Process for 3NF
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
Transitive Dependency
Course No --> Instructor No --> Instructor Name
Example
Source url:-https://codeandwork.github.io/courses/cs/database_normalization.html
Boyce-Codd Normal Form (BCNF)
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
BCNF Example
Student_id | Major | Advisor |
111 | Physics | Smith |
111 | Music | Chan |
320 | Math | Dobbs |
671 | Physics | White |
803 | Physics | Smith |
Consider the following table (St_Maj_Adv).
The semantic rules (business rules applied to the database) for this table are:
The functional dependencies for this table are listed below.
The first one is a candidate key; the second is not.
Anomalies for this table include:
Note: No single attribute is a candidate key.
PK can be Student_id, Major or Student_id, Advisor
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
BCNF Example – contd.
Student_id | Advisor |
111 | Smith |
111 | Chan |
320 | Dobbs |
671 | White |
803 | Smith |
Advisor | Major |
Smith | Physics |
Chan | Music |
Dobbs | Math |
White | Physics |
St_Adv table
Adv_Maj table
https://opentextbc.ca/dbdesign01/chapter/chapter-12-normalization/
Fourth Normal Form (4NF)
https://www.studytonight.com/dbms/fourth-normal-form.php
Multi Valued Dependency (MVD)
https://www.studytonight.com/dbms/fourth-normal-form.php
4NF - Example
https://en.wikipedia.org/wiki/Fourth_normal_form
pizza varieties offered by a restaurant are not affected by delivery area
Lossless Join Decomposition
Relation Decomposition
Lossless Join Decomposition
Lossless Join Decomposition
Lossless Join Decomposition
{for each functional dependency X gY in F
{for all rows in S which have the same symbols in the columns corresponding to attributes in X
{make the symbols in each column that correspond to an attribute in Y be the same in all these rows as follows:
If any of the rows has an “a” symbol for the column, set the other rows to that same “a” symbol in the column.
If no “a” symbol exists for the attribute in any of the rows, choose one of the “b” symbols that appear in one of the rows for the attribute and set the other rows to that same “b” symbol in the column ;};
};
};
Lossless Join Decomposition
Join Dependency and 5NF
JD - Definition:
* (pR1(r), pR2(r), ..., pRn(r)) = r
Fifth normal form
Fifth normal form
Source:-https://en.wikipedia.org/wiki/Fifth_normal_form
Example - 5NF
Source:-https://en.wikipedia.org/wiki/Fifth_normal_form
Example - 5NF
Source:-https://en.wikipedia.org/wiki/Fifth_normal_form
Note:- A table T is in fifth normal form (5NF) or Project-Join Normal Form (PJNF) if it cannot have a lossless decomposition into any number of smaller tables.
Example
SUBJECT | LECTURER | SEMESTER |
Computer | Anshika | Semester 1 |
Computer | John | Semester 1 |
Math | John | Semester 1 |
Math | Akash | Semester 2 |
Chemistry | Praveen | Semester 1 |
In the above table, John takes both Computer and Math class for Semester 1 but he doesn't take Math class for Semester 2.
In this case, combination of all these fields required to identify a valid data.
Suppose we add a new Semester as Semester 3 but do not know about the subject and who will be taking that subject so we leave Lecturer and Subject as NULL.
But all three columns together acts as a primary key, so we can't leave other two columns blank.
So to make the above table into 5NF, we can decompose it into three relations P1, P2 & P3:
p3
SEMESTER | SUBJECT |
Semester 1 | Computer |
Semester 1 | Math |
Semester 1 | Chemistry |
Semester 2 | Math |
SUBJECT | LECTURER |
Computer | Anshika |
Computer | John |
Math | John |
Math | Akash |
Chemistry | Praveen |
SEMSTER | LECTURER |
Semester 1 | Anshika |
Semester 1 | John |
Semester 1 | John |
Semester 2 | Akash |
Semester 1 | Praveen |
p2
p1
Inclusion Dependency
Inclusion Dependency
"Logical Database Design with Inclusion Dependencies" by Tok Wang LING and Cheng Hian GOH Department of Information Systems & Computer Science, National University of Singapore.
axiomatization for INDs