Understanding Second Normal Form (2NF) in Database Design
Understanding Second Normal Form (2NF) in Database Design
What is Second Normal Form (2NF)?
Second Normal Form (2NF) is an important step in database normalization. It helps reduce redundancy and ensures data dependencies make sense.
Rules for 2NF:
- The table must be in First Normal Form (1NF).
- The table should not have any partial dependencies (i.e., no non-prime attribute is partially dependent on any candidate key).
How Do You Achieve 2NF?
To convert your table into Second Normal Form, follow these steps:
-
Find the Candidate Keys (C.K.)
Candidate Key: A minimal set of attributes that can uniquely identify a row in a table. -
Identify Prime and Non-Prime Attributes
- Prime Attributes: Attributes that are part of any candidate key.
- Non-Prime Attributes: Attributes that are NOT part of any candidate key.
-
Detect Partial Dependencies
- Partial Dependency: When a non-prime attribute is dependent on part (not all) of a candidate key.
-
Remove Partial Dependencies
- Break the table into smaller tables so that non-prime attributes are fully dependent on the whole candidate key.
Example: Applying 2NF
Suppose you have a relation:
R(A, B, C, D)
And these functional dependencies:
- A, B → D
- B → C
Let’s analyze:
- Candidate Key (C.K.): AB (because (AB)+ = ABCD)
- Prime Attributes: A, B (part of the C.K.)
- Non-Prime Attributes: C, D (not part of the C.K.)
Detecting Partial Dependency:
Check if any non-prime attribute is dependent on just a part of the C.K.:
- C is dependent only on B (B → C). Since B alone is part of the C.K. (AB), this is a partial dependency.
Result:
The table is not in 2NF because of the partial dependency B → C.
Resolving Partial Dependencies
Step 1: Create two new tables:
-
Table 1: Contains the full candidate key and attributes fully dependent on it
R1(A, B, D) -
Table 2: Contains the part of the C.K. with the partially dependent non-prime attribute
R2(B, C)
Now, all non-prime attributes are fully functionally dependent on the whole candidate key in their respective tables, satisfying 2NF.
Summary Table
| Table Name | Attributes | Candidate Keys | Notes |
|---|---|---|---|
| R1 | A, B, D | AB | Fully dependent on AB |
| R2 | B, C | B | C is fully dependent on B |
Key Takeaway:
Second Normal Form helps eliminate partial dependencies, promoting a more robust and organized database structure.
Comments
Post a Comment