First Normal Form (1NF) in DBMS
The First Normal Form (1NF) is the first step in the normalization process of organizing data within a relational database to reduce redundancy and improve data integrity. A relation (table) is said to be in 1NF if it adheres to the following rules:
1. Atomic Values:
- Each attribute (column) contains only atomic (indivisible) values. This means values in each column are indivisible units and there should be no sets, arrays, or lists.
- For example, a column called "Phone Numbers" shouldn't contain multiple phone numbers for a single record. Instead, you'd typically break it into additional rows or another related table.
2. Primary Key:
- Each table should have a primary key that uniquely identifies each row. This ensures that each row in the table can be uniquely identified.
3. No Duplicate Rows:
- There shouldn’t be any duplicate rows in the table. This is often ensured by the use of the primary key.
4. Order Doesn't Matter:
- The order in which data is stored doesn't matter in the context of 1NF (or any of the normal forms). Relational databases don't guarantee an order for rows in a table unless explicitly sorted.
5. Single Valued Attributes:
- Columns should not contain multiple values of the same type. For example, a column "Skills" shouldn't contain a list like "Java, Python, C++" for a single record. Instead, these skills should be split across multiple rows or placed in a separate related table.
Example for First Normal Form (1NF)
Consider a table with a structure:
| Student_ID | Subjects |
|------------|-------------------|
| 1 | Math, English |
| 2 | English, Science |
| 3 | Math, History |
The table above is not in 1NF because the "Subjects" column contains multiple values.
To transform it to 1NF:
| Student_ID | Subject |
|------------|-----------|
| 1 | Math |
| 1 | English |
| 2 | English |
| 2 | Science |
| 3 | Math |
| 3 | History |
Now, each combination of "Student_ID" and "Subject" is unique, and every attribute contains only atomic values, ensuring the table is in 1NF.
Achieving 1NF is a fundamental step in database normalization, laying the foundation for further normalization processes to eliminate redundancy and ensure data integrity.