2 Normal Form
The Second Normal Form (2NF) is a concept in database normalization that builds upon the First Normal Form (1NF). It addresses issues related to partial dependencies in a relational database. To be in 2NF, a table must satisfy the following conditions:
It must already be in 1NF, which means that it contains only atomic values (no repeating groups or arrays in columns).
It should not have partial dependencies, which occur when non-key attributes (attributes not part of the primary key) depend on only part of a candidate key.
In simpler terms, 2NF eliminates redundancy and ensures that all non-key attributes are functionally dependent on the entire primary key, not just part of it.
Here's an example to illustrate 2NF:
Consider a table called Orders
with the following attributes:
1
101
Laptop
1001
Alice
2
2
102
Smartphone
1002
Bob
3
3
101
Laptop
1003
Carol
1
In this table:
OrderID
is the primary key.ProductID
is part of the candidate key because it identifies a product within an order.CustomerID
is also part of the candidate key because it identifies a customer associated with an order.ProductName
is functionally dependent onProductID
.CustomerName
is functionally dependent onCustomerID
.Quantity
is functionally dependent on bothOrderID
andProductID
because it represents the quantity of a specific product in a specific order.
However, there's a problem related to partial dependency. The Quantity
attribute depends on ProductID
, which is only part of the candidate key. This violates the 2NF because non-key attributes should depend on the entire candidate key.
To bring this table into 2NF, you should split it into two separate tables: one for orders and another for order details. Here's how it might look in 2NF:
Table: Orders
1
1001
2
1002
3
1003
Table: OrderDetails
1
101
2
2
102
3
3
101
1
In this revised structure, each table adheres to 2NF. The Quantity
attribute now depends on the entire primary key (composite key of OrderID
and ProductID
). This eliminates partial dependencies and reduces data redundancy, making the database more efficient and easier to manage.
Last updated
Was this helpful?