Third Normal Form: 3NF

A table is in Third Normal Form if: (1) it is already in 2NF, and (2) it has no transitive dependency.

Informal definition — transitive dependency

A transitive dependency means a non-key attributedepends on another non-key attribute.
A transitive dependency happens when:
  A → B  and  B → C
So indirectly:  A → C

In database terms: Primary key → Non-key attribute → Another non-key attribute

Example

Employee_IDEmployee_NameProject_IDProject_NameProject_Location
E01RahimP01Hospital Management SystemDhaka
E02KarimP02Banking SystemChattogram
E03MinaP01Hospital Management SystemDhaka
E04SumiP03Library SystemRajshahi

Here, the primary key is Employee_ID. Functional dependencies:

Employee_ID → Employee_Name, Project_ID — because one employee has one name and is assigned to one project.
Project_ID → Project_Name, Project_Location — because one project ID determines the project name and location.
Employee_ID does not uniquely identify the Project_Name and Project_Location — it only reaches them through Project_ID. So indirectly:
Employee_ID → Project_ID → Project_Name, Project_Location
Key  →  Non-key  →  Non-key
This is called a transitive dependency, and it violates 3NF.

Problems caused by the transitive dependency

AnomalyWhat goes wrong
UpdateIf the location of project P01 changes from Dhaka to Gazipur, it must be updated in multiple rows. If only one row is changed the database becomes inconsistent.
InsertionA new project cannot be inserted unless at least one employee is assigned to it — a new project P04 cannot be stored properly without employee information.
DeletionIf employee E04 is deleted, and that employee is the only person assigned to project P03, then information about P03 may also be lost.

Solution

Break the table based on functional dependency:

Employee table

Employee_IDEmployee_NameProject_ID
E01RahimP01
E02KarimP02
E03MinaP01
E04SumiP03

Project table

Project_IDProject_NameProject_Location
P01Hospital Management SystemDhaka
P02Banking SystemChattogram
P03Library SystemRajshahi

Solution validation

Functional DependencyValid or Not
Employee_ID → Employee_NameValid
Employee_ID → Project_IDValid
Functional DependencyValid or Not
Project_ID → Project_NameValid
Project_ID → Project_LocationValid
This removes the transitive dependency.

Formal definition of 3NF

For every functional dependency X → Y, the table is in 3NF if at least one of these is true:
  • X is a super key, or
  • Y is a prime attribute.
A prime attribute means an attribute that is part of any candidate key. This definition is more general and mathematically accurate.
Form of X → YAllowed in 3NF?
super key → prime attributeAllowed ✔
super key → non-prime attributeAllowed ✔
non-super key → prime attributeAllowed ✔
non-super key → non-prime attributeNOT allowed ✘

Applying the formal definition to the Employee table

3NF-abigCheck the Employee/Project table with the formal definition.

Another example — when the informal test cannot be used

Student_IDCourse_IDInstructor
S01CSE101Dr. Hasan
S02CSE101Dr. Hasan
S03CSE102Dr. Karim
S04CSE102Dr. Karim
S01CSE102Dr. Karim
Assume the rules are: (1) a student can take many courses; (2) a course can be taught by only one instructor.
3NF-bbigIs the Student / Course / Instructor table in 3NF?

Next: Boyce-Codd Normal Form →