What is a star schema?
Model answer
A star schema is a data warehouse model with a central fact table surrounded by dimension tables, which looks like a star.
The fact table records business events or measurements, one row per event at a chosen grain, such as one row per order line. It holds numeric measures (quantity, amount) and foreign keys to the dimensions.
The dimension tables describe the context: who, what, where, when. Examples are customer, product, store and date. They are wide and denormalized, with descriptive attributes used for filtering and grouping.
SELECT d.month, p.category, SUM(f.amount) AS revenue
FROM fact_sales f
JOIN dim_date d ON d.date_key = f.date_key
JOIN dim_product p ON p.product_key = f.product_key
GROUP BY d.month, p.category;
Benefits: simple queries with few joins, good performance and models that business users understand. A snowflake schema normalizes the dimensions further, saving space but adding joins. Always declare the grain first, because it fixes what each row means.
Key points
- A central fact table joined to denormalized dimension tables
- Facts hold measures and keys; dimensions hold descriptive context
- Declare the grain of the fact table first
- Simple, fast queries; snowflake normalizes dimensions at the cost of joins
Likely follow-ups
- What is the difference between a fact table and a dimension table?
- What is a degenerate dimension?
Common mistakes
- Mixing different grains in one fact table
- Normalizing dimensions heavily and losing the simplicity