[#4]. Database Normalization: 1NF, 2NF, 3NF Simplified! | MySQL Tutorial |
HTML-код
- Опубликовано: 27 дек 2024
- [#4] Database Normalization: 1NF, 2NF, 3NF Simplified! | MySQL Tutorial | #ITTECH
Normalization in MySQL refers to organizing a database into structured tables to reduce redundancy and improve data integrity. It involves decomposing large tables into smaller, related tables and defining relationships between them.
Objectives of Normalization:
1. **Eliminate redundancy**: Avoid storing the same data in multiple places.
2. **Ensure data integrity**: Prevent anomalies during insert, update, or delete operations.
3. **Improve efficiency**: Minimize storage and make queries faster by eliminating unnecessary data.
Normal Forms:
Normalization typically involves achieving various "normal forms," each with specific rules:
---
#### *1. First Normal Form (1NF)*
*Rules:*
Each column must contain atomic (indivisible) values.
Each row must be unique (have a primary key).
No repeating groups or arrays in a column.
*Example (Not in 1NF):*
| OrderID | Product |
|---------|-----------------|
| 1 | Pen, Notebook |
*Normalized (1NF):*
| OrderID | Product |
|---------|-----------|
| 1 | Pen |
| 1 | Notebook |
---
#### *2. Second Normal Form (2NF)*
*Rules:*
Must satisfy 1NF.
Remove partial dependency: All non-key columns must depend on the entire primary key.
*Example (Not in 2NF):*
| OrderID | Product | ProductPrice |
|---------|-----------|--------------|
| 1 | Pen | 10 |
| 1 | Notebook | 20 |
*Problem:* `ProductPrice` depends only on `Product`, not the full primary key (`OrderID, Product`).
*Normalized (2NF):*
1. *Orders Table*
| OrderID | Product |
|---------|-----------|
| 1 | Pen |
| 1 | Notebook |
2. *Products Table*
| Product | ProductPrice |
|-----------|--------------|
| Pen | 10 |
| Notebook | 20 |
---
#### *3. Third Normal Form (3NF)*
*Rules:*
Must satisfy 2NF.
Remove transitive dependency: Non-key columns must depend only on the primary key.
*Example (Not in 3NF):*
| OrderID | CustomerID | CustomerName |
|---------|------------|--------------|
| 1 | 101 | Alice |
*Problem:* `CustomerName` depends on `CustomerID`, not directly on `OrderID`.
*Normalized (3NF):*
1. *Orders Table*
| OrderID | CustomerID |
|---------|------------|
| 1 | 101 |
2. *Customers Table*
| CustomerID | CustomerName |
|------------|--------------|
| 101 | Alice |
Thank sir , your explanation technique is very clear, i want to learn SQL for data scientist or machine learning engineer role can you please tell me which topic are more useful for these roles