Chapter 5
Chapter 5
5. Database normalization
[email protected]
Chapter 5. Database normalization
• Database normalization
• First normal form (1NF)
• Second normal form (2NF)
• Third normal form (3NF)
• Boyce and Codd normal form (BCNF)
• Database denormalization
Database normalization
• Insert anomaly
• For a new admission, if the group is not explicitly set to accept NULL values,
the record cannot be inserted
• The specialization of a student is not set until the 3rd year of study
• Update anomaly
• If a student transfers from one group to another, this might imply changing
the tutor as well,
• If this is not handled appropriately, it will lead to data inconsistency
• Delete anomaly
• In the students table, we have both the student records and the groups
• If the student records are deleted, the group information is lost too
First normal form (1NF)
• Technically, this structure does not violate the first normal form,
since the values are atomic
• Informally, they still represent a repeating group (they are
conceptually the same attribute)
• What happens if more than two phone numbers are needed? How
many columns should be added?
id first_name last_name group … telephone_1 telephone_2
1 Bob Belcher 441F … 0754.324.156
2 Teddy Francisco 441F … 0752 148 569 0766 59 08 72
3 Courtney Wheeler 442F …
4 Henry Haber 442F … +4 (021) 345 76 33
First normal form (1NF)
• One possible resolution which would respect the first normal form
is to split the groups of strings or columns into atomic entities and
ensure that no row contains more than one phone number
• In this case, the id is no longer unique and instead the primary key
becomes the combination of id and phone number
courses
id title …
1 Information Theory …
2 Databases …
1 Information Theory …
schedules
course_id date room capacity …
1 2018-11-28 A01 15 …
2 2018-11-29 A04 12 …
1 2018-12-05 A03 20 …
Third normal form (3NF)
enrolments
student_id course professor
1 Java John Smith
1 Databases Anthony Page
2 Databases Laura Palmer
3 C++ Michael Angelo
4 Java John Smith
enrolments
student_id course professor
1 Java John Smith
1 Databases Anthony Page
2 Databases Laura Palmer
3 C++ Michael Angelo
4 Java John Smith
enrolments
student_id professor_id
1 1
1 2
2 3
3 4
4 1
professors
id professor course
1 John Smith Java
2 Anthony Page Databases
3 Laura Palmer Databases
4 Michael Angelo C++
Database denormalization