DBMS Notes
A relation is in Second Normal Form (2NF) if it satisfies two conditions: first, it must already be in First Normal Form (1NF), and second, every non-prime...
Definition
A relation is in Second Normal Form (2NF) if it satisfies two conditions: first, it must already be in First Normal Form (1NF), and second, every non-prime attribute must be fully functionally dependent on the entire primary key. In other words, there should be no partial dependencies — no non-key attribute should depend on only a part of a composite primary key.
To understand this clearly, let us first define the key terms. A prime attribute is any attribute that is part of a candidate key. A non-prime attribute is any attribute that is not part of any candidate key. A partial dependency occurs when a non-prime attribute depends on a proper subset of a composite candidate key rather than the full key.
An important observation: if a relation has a single-attribute primary key (not composite), it is automatically in 2NF because partial dependency can only occur when the primary key consists of multiple attributes. Partial dependency means depending on "part of" the key — if the key has only one attribute, there is no "part" to depend on.
Decomposition to Achieve 2NF
The solution is to decompose the relation by removing partial dependencies into separate relations:
Before (1NF but not 2NF)
OrderDetail(OrderID, ProductID, ProductName, Quantity, UnitPrice)
Step 1: Identify partial FDs:
ProductID → ProductName, UnitPrice
Step 2: Create a new relation for each partial dependency:
Product(ProductID, ProductName, UnitPrice)
Step 3: Remove those attributes from the original relation (keep the FK):
OrderDetail(OrderID, ProductID, Quantity)
Result (now in 2NF)
Product(ProductID, ProductName, UnitPrice) ← PK: ProductID
OrderDetail(OrderID, ProductID, Quantity) ← PK: (OrderID, ProductID)
FK: ProductID → Product
After decomposition, ProductName and UnitPrice are stored exactly once per product. The OrderDetail table only stores the quantity for each order-product combination, with a foreign key linking back to the Product table.
Detailed Example: Student-Course Database
Consider a university enrollment scenario:
| Primary Key | (StudentID, CourseID) |
| StudentID | StudentName, StudentEmail (partial — depends only on StudentID) |
| CourseID | CourseName, Credits (partial — depends only on CourseID) |
| (StudentID, CourseID) | Grade (full — needs both attributes) |
| - Student "Rahul" enrolled in 5 courses | name and email repeated 5 times |
| - Course "DBMS" has 60 students | course name and credits repeated 60 times |
Decomposition to 2NF:
| Student(StudentID, StudentName, StudentEmail) ← PK | StudentID |
| Course(CourseID, CourseName, Credits) ← PK | CourseID |
| Enrollment(StudentID, CourseID, Grade) ← PK | (StudentID, CourseID) |
| FK: StudentID | Student |
| FK: CourseID | Course |
Now each student's information is stored once, each course's information is stored once, and the Enrollment table only records the relationship and grade.
Visual Representation of 2NF Violation
| Product | OrderDetail | |
|---|---|---|
| ───────── | ─────────── | |
| ProductID (PK) | ◄─── | ProductID (FK) |
| ProductName | OrderID (PK) | |
| UnitPrice | Quantity |
Anomalies Eliminated by 2NF
| Anomaly Type | Before 2NF | After 2NF |
|---|---|---|
| Insertion | Cannot add a new product without an order | Can insert product independently |
| Deletion | Deleting last order for a product loses product info | Product exists independently |
| Update | Price change requires updating many rows | Price stored once, update once |
Algorithm for Converting to 2NF
- Identify the primary key (must be composite for partial dependency to exist)
- List all functional dependencies
- For each FD where the determinant is a proper subset of the primary key, that is a partial dependency
- Create a new relation with the partial key as primary key and its dependent attributes
- Remove the dependent attributes from the original relation (keep the partial key as FK)
- Repeat until no partial dependencies remain
Important Points to Remember
- 2NF only addresses partial dependencies — transitive dependencies may still exist (handled by 3NF)
- Relations with single-attribute primary keys are automatically in 2NF
- 2NF is a necessary step toward higher normal forms but is not sufficient for a fully normalized design
- In practice, most well-designed databases naturally satisfy 2NF because designers intuitively separate entity information into distinct tables
- The decomposition must be lossless — joining the decomposed tables must reproduce the original data exactly
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Second Normal Form (2NF) — Database Management Systems.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Database Management Systems (DBMS) topic.
Search Terms
dbms, database management systems (dbms), unit, second, normal, form, second normal form (2nf) — database management systems
Related Database Management Systems (DBMS) Topics