Second Normal Form (2NF) - Detailed Explanation
Second Normal Form (2NF) – Detailed Explanation
Second Normal Form (2NF) focuses on removing partial dependency so that every non-key attribute depends on the entire primary key, not just part of it.
Concept of Full Functional Dependency
2NF is based on the idea of full functional dependency.
Full Functional Dependency
A functional dependency X → Y is full if:
-
Removing any attribute from X makes the dependency invalid.
Example
-
Ssn alone → Hours ❌
-
Pnumber alone → Hours ❌
Therefore this dependency is full functional dependency.
Partial Dependency
A dependency is partial if part of the key can determine an attribute.
Example:
But actually:
So the attribute Ename depends only on part of the key (Ssn).
This is called partial dependency, and it violates 2NF.
Definition of Second Normal Form
A relation schema R is in Second Normal Form (2NF) if:
Every nonprime attribute A in R is fully functionally dependent on the primary key of R.
Important Terms
| Term | Meaning |
|---|---|
| Prime attribute | Attribute that is part of a primary key |
| Nonprime attribute | Attribute that is NOT part of any primary key |
| Full dependency | Attribute depends on whole key |
| Partial dependency | Attribute depends on part of key |
Key Rule for 2NF
2NF is concerned only when the primary key is composite (multiple attributes).
If the primary key has only one attribute, the relation is automatically in 2NF.
Example: EMP_PROJ Relation
Consider the relation:
Primary Key:
Functional Dependencies:
Problems in This Relation
Partial Dependency 1
Ename depends on only part of the primary key.
Partial Dependency 2
These attributes depend only on Pnumber, not the full key.
Therefore
The relation is:
Converting to Second Normal Form
To achieve 2NF, we separate attributes that depend on part of the key.
Step 1: Employee Relation
Step 2: Project Relation
Step 3: Works Relation
Primary key:
Final Result
| Relation | Key |
|---|---|
| EMPLOYEE(EP2) | Ssn |
| PROJECT(EP3) | Pnumber |
| WORKS_ON(EP1) | (Ssn, Pnumber) |
Now every non-key attribute depends on the whole key.
Why 2NF is Important
2NF helps eliminate:
Data Redundancy
Repeated storage of the same information.
Update Anomaly
Changing a value in many rows.
Insertion Anomaly
Cannot insert data without other data.
Deletion Anomaly
Deleting one tuple removes important information.
Practice Questions: Normalize into 2NF
Question 1
Consider the relation:
ENROLLMENT(Student_ID, Course_ID, Student_Name, Course_Name, Instructor, Grade)
Functional Dependencies:
-
(Student_ID, Course_ID) → Grade
-
Student_ID → Student_Name
-
Course_ID → Course_Name, Instructor
Task:
-
Identify the candidate key.
-
Determine the partial dependencies.
-
Convert the relation into 2NF.
Question 2
Consider the relation:
ORDER_DETAILS(Order_ID, Product_ID, Product_Name, Quantity, Unit_Price, Customer_ID, Customer_Name)
Functional Dependencies:
-
(Order_ID, Product_ID) → Quantity
-
Product_ID → Product_Name, Unit_Price
-
Order_ID → Customer_ID
-
Customer_ID → Customer_Name
Task:
-
Identify the primary key.
-
Find partial dependencies.
-
Decompose the relation into 2NF relations.
Question 3
Consider the relation:
SUPPLIER_PART(Supplier_ID, Part_ID, Supplier_Name, Part_Name, Price, Quantity)
Functional Dependencies:
-
(Supplier_ID, Part_ID) → Quantity
-
Supplier_ID → Supplier_Name
-
Part_ID → Part_Name, Price
Task:
-
Identify the candidate key.
-
Identify partial dependencies.
-
Convert the relation into 2NF.
Question 4
Consider the relation:
STUDENT_COURSE(Student_ID, Course_ID, Student_Name, Course_Name, Credits, Marks)
Functional Dependencies:
-
(Student_ID, Course_ID) → Marks
-
Student_ID → Student_Name
-
Course_ID → Course_Name, Credits
Task:
-
Identify the primary key.
-
Find partial dependencies.
-
Normalize the relation into 2NF.
Question 5
Consider the relation:
PROJECT_ASSIGNMENT(Employee_ID, Project_ID, Employee_Name, Project_Name, Hours_Worked, Project_Location)
Functional Dependencies:
-
(Employee_ID, Project_ID) → Hours_Worked
-
Employee_ID → Employee_Name
-
Project_ID → Project_Name, Project_Location
Task:
-
Identify the candidate key.
-
Identify partial dependencies.
-
Decompose the relation into 2NF.
Answers
Answer 1
Candidate Key:
(Student_ID, Course_ID)
Partial Dependencies:
-
Student_ID → Student_Name
-
Course_ID → Course_Name, Instructor
2NF Relations
-
STUDENT(Student_ID, Student_Name)
-
COURSE(Course_ID, Course_Name, Instructor)
-
ENROLLMENT(Student_ID, Course_ID, Grade)
Answer 2
Primary Key:
(Order_ID, Product_ID)
Partial Dependencies:
-
Product_ID → Product_Name, Unit_Price
-
Order_ID → Customer_ID
2NF Relations
-
PRODUCT(Product_ID, Product_Name, Unit_Price)
-
ORDER(Order_ID, Customer_ID)
-
ORDER_DETAILS(Order_ID, Product_ID, Quantity)
-
CUSTOMER(Customer_ID, Customer_Name)
Answer 3
Candidate Key:
(Supplier_ID, Part_ID)
Partial Dependencies:
-
Supplier_ID → Supplier_Name
-
Part_ID → Part_Name, Price
2NF Relations
-
SUPPLIER(Supplier_ID, Supplier_Name)
-
PART(Part_ID, Part_Name, Price)
-
SUPPLIER_PART(Supplier_ID, Part_ID, Quantity)
Answer 4
Primary Key:
(Student_ID, Course_ID)
Partial Dependencies:
-
Student_ID → Student_Name
-
Course_ID → Course_Name, Credits
2NF Relations
-
STUDENT(Student_ID, Student_Name)
-
COURSE(Course_ID, Course_Name, Credits)
-
STUDENT_COURSE(Student_ID, Course_ID, Marks)
Answer 5
Candidate Key:
(Employee_ID, Project_ID)
Partial Dependencies:
-
Employee_ID → Employee_Name
-
Project_ID → Project_Name, Project_Location
2NF Relations
-
EMPLOYEE(Employee_ID, Employee_Name)
-
PROJECT(Project_ID, Project_Name, Project_Location)
-
PROJECT_ASSIGNMENT(Employee_ID, Project_ID, Hours_Worked)

Comments
Post a Comment