Normal form: An Overview
Normal forms are a concept in database design that refer to the organization of data in a database. There are several different types of normal forms, each of which has specific rules for organizing data in a way that minimizes redundancy and dependency.
First Normal Form (1NF)
The first normal form (1NF) is the most basic and fundamental normal form. It is defined as follows:
- A database table is in 1NF if and only if it satisfies the following two conditions:
- Each cell in the table must contain a single value, not a list of values or a combination of values
- Each column in the table must have a unique name
In 1NF, data is organized into tables with rows and columns, similar to a spreadsheet. Each row represents a unique entity (such as a customer or an order), and each column represents an attribute of that entity (such as a customer's name or an order's total cost).
Second Normal Form (2NF)
The second normal form (2NF) builds on the principles of 1NF and adds an additional requirement:
- A database table is in 2NF if and only if it satisfies the following three conditions:
- It is in 1NF
- It does not have any partial dependencies
- It does not have any transitive dependencies
Partial dependencies occur when an attribute in a table depends on only part of a composite primary key (a primary key made up of multiple columns). For example, consider the following table:
| Customer ID |
Customer Name |
City |
| 1 |
Alice |
New York |
| 2 |
Bob |
Chicago |
In this table, the primary key is the combination of the Customer ID and Customer Name columns. The City column depends on the Customer ID column, but not on the Customer Name column. This is a partial dependency, because the City attribute depends on only part of the primary key. To fix this issue, the City attribute should be moved to a separate table, with a foreign key linking back to the Customer table.
Transitive dependencies occur when an attribute in a table depends on another attribute that is not part of the primary key. For example, consider the following table:
| Customer ID |
Customer Name |
Phone Number |
Area Code |
| 1 |
Alice |
555-1212 |
555 |
Normal Forms