OLTP vs OLAP & Star Schemas in SQL
Row stores for transactions, columnar marts for analytics
OLTP handles many small concurrent reads/writes on normalized row stores — orders, banking. OLAP runs heavy aggregations over huge history — dashboards, warehouses, star schemas (central fact + denormalized dimensions). Design follows workload: indexes + normalized for OLTP; columnar + pre-aggregated marts for OLAP.
OLTP transacts
Many small concurrent reads/writes, normalized row store, PK/FK indexes, short txns.
OLAP scans
Few huge aggregations over history — dashboards, warehouses, columnar.
Star the marts
Fact (sales) + dimensions (date/product/store) — denormalized for scan speed.
Feed both shapes
3NF system of record + ETL-fed marts; OLAP reads to replicas/matviews.
1-- star: fact joins dimensions2SELECT d.month, SUM(f.amount) FROM fact_sales f JOIN dim_date d ON f.date_id = d.id GROUP BY d.month;
| month | revenue |
|---|---|
| 2024-01 | 120000 |
| 2024-02 | 135000 |
Fact holds one row per sale; dimensions decode ids to months, products, stores. Columnar engine scans amount only — not whole rows — for the sum.
Monthly revenue from star
Fact joins date dimension, columnar sums amount.
1SELECT d.month, SUM(f.amount) AS revenue FROM fact_sales f JOIN dim_date d ON f.date_id = d.id GROUP BY d.month ORDER BY d.month;
| month | revenue |
|---|---|
| 2024-01 | 120000 |
| 2024-02 | 135000 |
Pick the store
Workload decides storage + shape.
1-- OLTP: orders(id PK, customer_id FK) — row store, short txn2-- OLAP: fact_sales(date_id, amount) — columnar, bulk scan
| workload | shape |
|---|---|
| OLTP | row + normalized + indexed |
| OLAP | columnar + star + pre-agg |
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Take the queries you just visualized and see the data structures that power real databases.