A table must:
Be in 1NF.
Have no partial dependency: every non-key attribute must depend on the whole candidate key, not just part of a composite key.
Before 2NF (Violates 2NF)
Student_ID (PK) | Course_ID (PK) | Student_Name | Course_Title | Grade |
|---|---|---|---|---|
101 | C01 | Aarav | SQL Basics | A |
101 | C02 | Aarav | Power BI | B+ |
102 | C01 | Priya | SQL Basics | A- |
The Problem:
Student_Namedepends only onStudent_ID, andCourse_Titledepends only onCourse_ID. OnlyGradedepends on both keys together.The Anomalies: If Aarav changes his name, you must update multiple rows (update anomaly). You also cannot add a new course until a student enrolls (insertion anomaly).
After 2NF (Decomposed into 3 Tables)
To reach 2NF, split the columns that depend on partial keys into their own dedicated tables.
1. Students Table (Student_ID is the primary key)
Student_ID (PK) | Student_Name |
|---|---|
101 | Aarav |
102 | Priya |
2. Courses Table (Course_ID is the primary key)
Course_ID (PK) | Course_Title |
|---|---|
C01 | SQL Basics |
C02 | Power BI |
3. Enrollments Table (Student_ID, Course_ID is the composite primary key)
Student_ID (PK, FK) | Course_ID (PK, FK) | Grade |
|---|---|---|
101 | C01 | A |
101 | C02 | B+ |
102 | C01 | A- |