Q1. What is normalization and why is it important?
basicAnswer
Normalization organizes data to reduce redundancy and improve integrity. Normal forms: 1NF (atomic values), 2NF (no partial dependencies), 3NF (no transitive dependencies). Benefits: Less storage, easier updates, data consistency. Trade-off: May need JOINs for queries.
Example Code
1-- Unnormalized (bad)
2CREATE TABLE orders (
3 id INT, customer_name VARCHAR, customer_email VARCHAR,
4 product_name VARCHAR, product_price DECIMAL
5);
6
7-- Normalized (good) - 3NF
8CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR, email VARCHAR);
9CREATE TABLE products (id INT PRIMARY KEY, name VARCHAR, price DECIMAL);
10CREATE TABLE orders (
11 id INT PRIMARY KEY,
12 customer_id INT REFERENCES customers(id),
13 product_id INT REFERENCES products(id)
14);