Schema Design & Normalization

Database Normalization

1NF — First Normal Form

  • Each column has atomic values

  • No repeating groups

-- ❌ Violates 1NF
CREATE TABLE orders (
    id INT,
    items VARCHAR(500)  -- "Surface Pro, Xbox, Keyboard" (multiple values in one field)
);

-- ✅ 1NF
CREATE TABLE order_items (
    order_id INT,
    product_id INT,
    quantity INT
);

2NF — No Partial Dependencies

All non-key columns depend on the whole primary key.

3NF — No Transitive Dependencies

Non-key columns depend only on the primary key, not on other non-key columns.

Common Design Patterns

One-to-Many

Many-to-Many

Self-Referencing (Hierarchical)

Choosing SQL vs NoSQL

Criteria
SQL (PostgreSQL/MySQL)
NoSQL (MongoDB/Redis)

Data structure

Fixed schema

Flexible/dynamic

Relationships

Complex joins

Embedded documents

Consistency

ACID guaranteed

Eventual consistency

Scaling

Vertical (mostly)

Horizontal

Best for

Financial, inventory

User profiles, catalogs

Last updated