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 β
ββββββ΄βββββββββ΄βββββββ ββββββ΄βββββββββββββββ