Skip to content

Lecture 35: Second Normal Form 2NF

  • by
  • 3 min read
Setting Up Our Environment

This lecture covers Second Normal Form (2NF). Once a table is in First Normal Form (1NF), the next step is to check if it satisfies Second Normal Form (2NF). The rule for 2NF is:

A table is in 2NF if it is in 1NF and every non-key attribute is fully functionally dependent on the entire primary key.

That sounds complicated, but the concept is simpler than the definition. It mainly applies to tables that have a composite primary key (a primary key made up of two or more columns). It means that no non-key column should depend on only *part* of the composite primary key.

An Example of a 2NF Violation

Let’s imagine a table that tracks which students are enrolled in which courses, and also stores the location of the course.

Let’s say the primary key for this table is the combination of `StudentID` and `CourseID`.

Enrollment Table (Violates 2NF)

StudentIDCourseIDStudentNameCourseLocation
101CS101AliceRoom 1A
101ENGL202AliceRoom 3B
102CS101BobRoom 1A

Let’s analyze the dependencies:

  • StudentName depends only on `StudentID`. It has nothing to do with the course. This is a partial dependency because `StudentName` depends on only a part of the composite primary key (`StudentID`, `CourseID`).
  • CourseLocation depends only on `CourseID`. It has nothing to do with the student. This is also a partial dependency.

This design leads to data redundancy. Alice’s name is repeated for every course she takes. The location of CS101 is repeated for every student enrolled in it. If the location of a course changes, you have to update it in many places.

Making it 2NF

To fix this, we must remove the partial dependencies by splitting the table into smaller tables, where each table has a single purpose.

Students Table

StudentID (PK)StudentName
101Alice
102Bob

Courses Table

CourseID (PK)CourseLocation
CS101Room 1A
ENGL202Room 3B

Enrollment Table

StudentID (FK)CourseID (FK)
101CS101
101ENGL202
102CS101
Setting Up Our Environment
Setting Up Our Environment

Now, the `StudentName` is stored only once per student. The `CourseLocation` is stored only once per course. The `Enrollment` table exists only to link students and courses. There are no more partial dependencies, and our design is in 2NF.

If a table is in 1NF and its primary key is a single column (not composite), then the table is automatically in 2NF.

In the Next Lecture…

We will cover the last of the common normal forms: Third Normal Form (3NF). 3NF deals with another type of problematic dependency called a transitive dependency.

Lecture 34: Database Normalization and 1NF

Najeeb Alam

Najeeb Alam

Technical writer specializes in developer, Blogging and Online Journalism. I have been working in this field for the last 20 years.