Different Normal Forms

What is Database Normalisation?

Database normalisation is the process of organising data in a relational database to reduce redundancy and improve integrity.

It involves structuring data across multiple tables using normal forms (1NF, 2NF, 3NF) to eliminate anomalies and maintain consistency.

Why Normalise a Database?

  • Minimises Data Redundancy: Ensures that data is not duplicated unnecessarily.
  • Prevents Data Anomalies: Reduces inconsistencies when updating or deleting data.
  • Improves Data Integrity: Maintains logical relationships between tables.
  • Enhances Query Performance: Optimises storage and retrieval efficiency.

Normal Forms

For this course, you need to be able to normalise a database to 3rd Normal Form.

To illustrate these processes, we shall use the example of Student Enrolment in Different Courses.

1NF (First Normal Form)

Definition: A table is in 1NF if there is a Primary Key and there are no repeating attributes, or groups of repeating attributes.

How to:

  1. Identify non-atomic values and repeating groups/columns
  2. Separate values into new rows

Identify non-atomic values and repeating groups/columns

A group of repeating attributes

StudentIDStudentNameCourses
1001Isla GreenMaths, Physics
1002Leo PatelBiology

or Repeating attributes

StudentIDStudentNameCourse1Course2
1001Isla GreenMathsPhysics
1002Leo PatelBiology-

Separate values into new rows

In 1NF:

StudentIDStudentNameCourse
1001Isla GreenMaths
1001Isla GreenPhysics
1002Leo PatelBiology

2NF (Second Normal Form)

Definition: A table is in 2NF if it is already in 1NF; and all fields are dependent on the whole (composite) key.

How to:

  1. Ensure the table is in 1NF
  2. Move attributes that depend only on part of a composite key into a separate table

The table is in 1NF. However, it is not in 2NF – StudentName only depends on StudentID

StudentIDCourseIDStudentName
1001M101Isla Green
1001P102Isla Green
1002B103Leo Patel

Move attributes that depend only on StudentID to a separate table

In 2NF:

Students Table
StudentIDStudentName
1001Isla Green
1002Leo Patel
Enrolment Table
StudentIDCourseID
1001M101
1001P102
1002B103

3NF (Third Normal Form)

Definition: A table is in 3NF if it is already in 2NF; and all attributes are only dependent on the primary key, and not on any non-key attributes (no transitive dependencies).

How to:

  1. Ensure the table is in 2NF
  2. Move attributes that depend on non-key attributes into a new related table

Not in 3NF – InstructorName depends on InstructorID, which is not a primary key

StudentIDCourseIDInstructorIDInstructorName
1001M101I001Ms Roberts
1001P102I002Dr Clark
1002B103I002Dr Clark

Move instructor details to a separate table

In 3NF:

Instructor Table
InstructorIDInstructorName
I001Ms Roberts
I002Dr Clark
Enrolment Table
StudentIDCourseIDInstructorID
1001M101I001
1001P102I002
1002B103I002

Comparison of Normal Forms

Normal Form Condition Key Concept
1NF All columns contain atomic values No repeating groups
2NF 1NF + No partial-key dependencies All attributes depend on the whole primary key
3NF 2NF + No transitive dependencies Non-key attributes do not depend on other non-key attributes

Important Normalisation Concepts

  • Atomicity: Each field contains only one value (1NF).
  • Unique Identification: Every record must be uniquely identifiable using a key.
  • Functional Dependencies: A relationship where one attribute uniquely determines another.
  • Partial-Key Dependencies: When an attribute depends on only part of a composite key (violates 2NF).
  • Transitive Dependencies: When a non-key attribute depends on another non-key attribute (violates 3NF).

 Key Takeaways

  • Database normalisation structures data efficiently by reducing redundancy.
  • 1NF: Ensures atomic values and unique rows.
  • 2NF: Eliminates partial dependencies on composite keys.
  • 3NF: Eliminates transitive dependencies for better consistency.
  • 1NF, 2NF, 3NF summarised as: The key, the whole key, and nothing but the key (so help me, Codd).
  • Applying normalisation ensures efficient storage, better query performance, and data integrity.