Systems30 min · Lesson 1 of 17
SQL Syntax & Normalization
The core of data integrity. Understanding 1NF, 2NF, 3NF and the power of JOINs for reliable data modeling.
The Relational Model
Databases ensure Data Integrity through normalization. By following normalization rules, we prevent data duplication and update anomalies.
-- Normalized schema example
CREATE TABLE customers (
customer_id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE orders (
order_id SERIAL PRIMARY KEY,
customer_id INT REFERENCES customers(customer_id),
order_date TIMESTAMPTZ DEFAULT NOW(),
status VARCHAR(50) DEFAULT 'pending'
);
-- JOIN to reconstruct the full view
SELECT c.email, o.order_id, o.order_date
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
WHERE c.email = 'user@example.com';
The Power of JOINs
Understanding Inner, Left, Right, and Full Outer Joins is the first step toward complex data reporting.