Careeroza
Third Normal Form (3NF)
Rules of 3NF
- The table is in 2NF.
- No transitive dependency: non-key columns depend only on the key, not on other non-key columns.
A well-known summary: every non-key column must depend on "the key, the whole key, and nothing but the key".
Example
Not in 3NF: DeptName depends on DeptID, which depends on EmployeeID.
| EmployeeID | Name | DeptID | DeptName |
|---|---|---|---|
| 1 | Rahul | 10 | Sales |
| 2 | Sara | 10 | Sales |
| 4 | Ananya | 20 | Support |
In 3NF:
| EmployeeID | Name | DeptID |
|---|---|---|
| 1 | Rahul | 10 |
| 2 | Sara | 10 |
| 4 | Ananya | 20 |
| DeptID | DeptName |
|---|---|
| 10 | Sales |
| 20 | Support |
Putting It Back Together
Example
Normalized tables are recombined with a join whenever needed:
CREATE TABLE Departments (DeptID INT PRIMARY KEY, DeptName VARCHAR(50));
CREATE TABLE Staff (EmployeeID INT PRIMARY KEY, Name VARCHAR(50), DeptID INT REFERENCES Departments(DeptID));
INSERT INTO Departments VALUES (10, 'Sales'), (20, 'Support');
INSERT INTO Staff VALUES (1, 'Rahul', 10), (2, 'Sara', 10), (4, 'Ananya', 20);
-- rename a department in ONE place
UPDATE Departments SET DeptName = 'Customer Success' WHERE DeptID = 20;
SELECT s.Name, d.DeptName FROM Staff s JOIN Departments d USING (DeptID);Result: 3 rows
| Name | DeptName |
|---|---|
| Rahul | Sales |
| Sara | Sales |
| Ananya | Customer Success |