Complete SQL Topics for Data Analysis
-> https://t.me/sqlspecialist/523
Let's also learn about Normalization today:
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. There are different normal forms, each with specific rules:
#### First Normal Form (1NF):
- Each column contains atomic (indivisible) values.
- There are no repeating groups or arrays.
#### Second Normal Form (2NF):
- Meets the requirements of 1NF.
- All non-key columns are fully functionally dependent on the primary key.
#### Third Normal Form (3NF):
- Meets the requirements of 2NF.
- Eliminates transitive dependencies, where non-key columns depend on other non-key columns.
#### Example:
Consider a denormalized table:
CREATE TABLE orders (Normalized to 3NF:
order_id INT PRIMARY KEY,
customer_name VARCHAR(50),
product_name VARCHAR(50),
price DECIMAL(10, 2)
);
CREATE TABLE orders (Normalization helps avoid data anomalies and ensures efficient database design.
order_id INT PRIMARY KEY,
customer_id INT,
product_id INT,
order_date DATE,
quantity INT,
total_price DECIMAL(10, 2)
);
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(50)
);
CREATE TABLE products (
product_id INT PRIMARY KEY,
product_name VARCHAR(50),
price DECIMAL(10, 2)
);
Share with credits: https://t.me/sqlspecialist
Hope it helps :)