KevsRobots Learning Platform
70% Percent Complete
By Kevin McAleer, 2 Minutes
Second Normal Form (2NF) is a concept in database normalization that builds upon the principles of First Normal Form (1NF) to further organize and eliminate redundancy in a relational database.
In Second Normal Form, a table must first satisfy the requirements of 1NF. Additionally, it should ensure that all non-key attributes (attributes not part of the primary key) are functionally dependent on the entire primary key, rather than just a portion of it.
To meet the requirements of 2NF:
To illustrate this, letβs consider a hypothetical table called βOrdersβ with the following columns: OrderID (primary key), ProductID (primary key), ProductName, and Quantity.
| OrderID | ProductID | ProductName | Quantity |
|---|---|---|---|
| 1 | 101 | Apple | 5 |
| 1 | 102 | Banana | 3 |
| 2 | 101 | Apple | 2 |
In this example, the combination of OrderID and ProductID serves as the composite primary key. However, the attribute βProductNameβ is functionally dependent on the ProductID alone, not the entire primary key. This violates the requirements of 2NF.
To normalize this table to 2NF, we would split it into two separate tables:
| OrderID | ProductID | Quantity |
|---|---|---|
| 1 | 101 | 5 |
| 1 | 102 | 3 |
| 2 | 101 | 2 |
| ProductID | ProductName |
|---|---|
| 101 | Apple |
| 102 | Banana |
By separating the data into two tables, we ensure that each table contains only the necessary attributes and that non-key attributes are fully dependent on the entire primary key.
The aim of achieving 2NF is to eliminate data redundancy and maintain data integrity by organizing data based on functional dependencies. It helps improve data structure, reduce anomalies during data modifications, and allows for efficient querying and data management.
You can use the arrows β β on your keyboard to navigate between lessons.
Comments