Lesson 35: Second Normal Form (2NF)
To achieve 2NF, a table must already be in 1NF, and it must satisfy an additional condition regarding composite keys.
Rule for 2NF
No non-key attribute is partially dependent on any candidate key.
This rule applies only when a table has a Composite Primary Key (a PK made up of two or more columns).
- Non-Key Attribute: Any column that is not part of the primary key.
- Partial Dependency: When a non-key attribute is determined by only a part of the composite key, not the whole key.
Violation Example: Order Details
Assume a composite PK: (OrderID, ProductID).
| OrderID (PK) | ProductID (PK) | ProductName | Quantity | Price |
|---|---|---|---|---|
| 100 | A | Keyboard | 2 | 50 |
| 101 | A | Keyboard | 1 | 50 |
ProductNameandPriceonly depend onProductID(a part of the key).Quantitydepends on the full key (OrderID+ProductID).
If the ProductName changes, we must update it for every order it appears in (redundancy).
Correction (Achieving 2NF)
We separate the partially dependent attributes into a new table:
ProductsTable: PK:ProductID. ContainsProductNameandPrice.OrderDetailsTable: Composite PK: (OrderID,ProductID). ContainsQuantity.
Now, ProductName is dependent only on the key in its own table, removing partial dependency.