Labs ICT
⭐ Pro Login

2NF and 3NF

Removing partial and transitive dependencies.

Second Normal Form (2NF)

A table is in 2NF if it's in 1NF AND every non-key column is fully functionally dependent on the entire primary key. This only matters for tables with composite primary keys.

Violation of 2NF


  NOT in 2NF: Partial dependency
  Enrollments table (PK: StudentID + CourseID)
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚StudentIDβ”‚CourseID β”‚Grade β”‚ StudentName      β”‚ CourseTitleβ”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ 1       β”‚ 101     β”‚ A    β”‚ Alice            β”‚ Databases β”‚
  β”‚ 2       β”‚ 101     β”‚ B    β”‚ Bob              β”‚ Databases β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  Problem:
  β€’ StudentName depends only on StudentID (not CourseID)
  β€’ CourseTitle depends only on CourseID (not StudentID)
  β€’ These are PARTIAL dependencies β€” they depend on part of the PK

Converting to 2NF


  IN 2NF: Remove partial dependencies

  Enrollments              Students            Courses
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚StudentIDβ”‚CourseID β”‚   β”‚ ID β”‚ Name    β”‚   β”‚ ID β”‚ Title  β”‚
  β”‚ Grade   β”‚         β”‚   β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”‚ 1  β”‚ Alice   β”‚   β”‚101 β”‚ DB     β”‚
  β”‚ 1       β”‚ 101     β”‚   β”‚ 2  β”‚ Bob     β”‚   β”‚    β”‚        β”‚
  β”‚ 2       β”‚ 101     β”‚   β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  StudentName β†’ Students table (depends on StudentID)
  CourseTitle β†’ Courses table (depends on CourseID)
  Grade stays in Enrollments (depends on both PK columns)

Third Normal Form (3NF)

A table is in 3NF if it's in 2NF AND there are no transitive dependencies β€” non-key columns should not depend on other non-key columns.


  NOT in 3NF: Transitive dependency
  Students
  β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ ID β”‚ Name    β”‚ DeptID β”‚ DeptName     β”‚
  β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ 1  β”‚ Alice   β”‚ 10     β”‚ Computer Sci β”‚
  β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  Problem: DeptName depends on DeptID (not directly on ID)
  ID β†’ DeptID β†’ DeptName (transitive!)

  Fix: Move DeptName to a separate Departments table
  Students              Departments
  β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ ID β”‚ Name   β”‚DeptIDβ”‚  β”‚ ID β”‚ Name         β”‚
  β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€  β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ 1  β”‚ Alice  β”‚ 10   β”‚  β”‚ 10 β”‚ Computer Sci β”‚
  β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜