Star schema

On this page 7

A star schema is a dimensional data modeling pattern in which one central fact table of numeric measurements is surrounded by several dimension tables that describe those measurements, such as date, product, customer and store. In data modeling, it is the standard structure for analytical databases and data warehouses, named for the star shape it forms in an ER diagram.

The fact table holds foreign keys to each dimension plus measures such as quantity or revenue, while each dimension is a single, deliberately denormalized table. This design favors simple, fast aggregation queries over the strict avoidance of redundancy that normalization brings to transactional systems.

Structure of a star schema

Every star schema has a declared grain: a precise statement of what one row in the fact table represents, such as one product on one sales receipt line. Choosing the grain first is the core discipline of dimensional modeling, because all measures and dimensions must be true at that grain.

ComponentContentExample
Fact tableForeign keys and numeric measuressales_fact with quantity and amount
Dimension tableDescriptive attributes for filtering and groupingproduct_dim with brand and category
Surrogate keyMeaningless integer key for each dimension rowproduct_key = 4182
Natural keyIdentifier from the source systemProduct SKU code
Date dimensionOne row per calendar day with attributesWeekday, month, fiscal quarter
Components of a star schema

Fact tables are usually narrow and very long, often with millions or billions of rows, while dimension tables are wide and comparatively short, often with dozens of descriptive columns. Each fact row relates to exactly one row in each dimension, a one-to-many relationship from dimension to fact.

Types of fact tables and measures

Fact tables come in three classic forms, distinguished by how and when rows are written. Mixing these forms in one table is a frequent source of wrong totals.

Fact table typeOne row representsTypical use
Transaction factA single event at a point in timeSales lines, payments, clicks
Periodic snapshotThe state at regular intervalsDaily account balances, monthly inventory
Accumulating snapshotA process instance updated through milestonesOrder from placement to delivery
Fact table types

Measures differ in how they can be summed. Additive measures such as revenue can be summed across all dimensions; semi-additive measures such as account balances cannot be summed over time; and non-additive measures such as ratios must be recomputed from their components rather than added.

Star schema compared with other models

The star schema sits between a fully normalized model and a single flat table. Its main neighbor is the snowflake schema, which normalizes dimensions into sub-tables.

ModelDimension structureBest fit
Star schemaOne denormalized table per dimensionBusiness intelligence and reporting
Snowflake schemaDimensions split into normalized sub-tablesLarge shared hierarchies, storage-sensitive designs
Third normal formFully normalized entitiesTransactional systems and enterprise integration layers
One big tableAll attributes flattened into the fact rowsColumnar engines with simple dashboards
Data vaultHubs, links and satellitesAuditable, history-preserving raw layers
Star schema versus related modeling approaches

Normalization removes redundancy to protect transactional updates, but analytics are mostly read-only and join-heavy. Repeating a category name on thousands of product rows costs little storage and saves joins, which is why star schemas accept controlled redundancy in dimensions.

Query engines exploit the shape directly. Many databases recognize star joins and filter the fact table using the selective dimension filters first, and columnar warehouses compress the repetitive dimension keys in fact tables very efficiently.

Handling change with slowly changing dimensions

Dimension attributes change over time: customers move, products change category. Slowly changing dimension techniques decide whether history is kept, and the choice determines whether past reports stay reproducible.

TypeHandling of a changeEffect on history
Type 1Overwrite the old valueHistory is restated with the new value
Type 2Add a new row with validity datesFacts keep the value valid at the time
Type 3Add a column for the previous valueLimited history of one prior value
Slowly changing dimension types

Type 2 is the most common choice when history matters. Each version receives its own surrogate key, so a sale recorded last year stays linked to the customer’s old region, while new sales link to the current version.

Design guidelines and common mistakes

Good star schemas follow a few consistent rules that keep queries simple and totals correct across reports.

  • Declare the grain before choosing any dimension or measure.
  • Use conformed dimensions, shared identically across fact tables, so different business processes can be compared.
  • Avoid nulls in foreign keys by pointing to an explicit unknown member row.
  • Do not snowflake by default; normalize a dimension only for a concrete reason.
  • Handle many-to-many relationships with a bridge table instead of duplicating fact rows.

The most damaging error is mixed grain, where daily totals and individual transactions share one fact table, causing double counting. Another is fan-out, where joining a fact table to a many-to-many relationship without a bridge multiplies measures and inflates revenue figures silently.

In a larger warehouse, several star schemas share their dimensions. Planning this with an enterprise bus matrix, a grid of business processes against conformed dimensions, prevents each team from building its own incompatible customer or product table. When queries over billions of fact rows become slow, aggregate fact tables at a coarser grain, such as daily sales per store, can serve common dashboards while the detailed table remains available for drill-down.

In everyday language

A star schema organizes business data like a receipt surrounded by reference cards. The receipt in the middle records what happened: how many items, what they cost. The cards around it explain the details: which product, which store, which day, which customer.

Because every detail is just one step away from the receipt, questions such as sales by region and month can be answered quickly. The design deliberately repeats some information on the cards to keep those answers simple.

Seen in the real world

A grocery chain with 200 stores wants daily sales reporting. The data team builds a sales_fact table at the grain of one product per receipt line, with keys to date, product, store, customer and promotion dimensions, and measures for quantity, sales amount and discount.

The product dimension tracks category changes as Type 2, so last year’s results remain comparable. Analysts in the business intelligence tool now answer questions such as weekly sales of dairy products by region during a promotion with a single star join, and reports that previously took hours of spreadsheet work refresh within minutes.