{"canonical_url":"https://engineer.company/glossary/star-schema/","content_markdown":"# Star schema\n\n## What it is\n\nA star schema is a way of laying out tables for analysis. One table in the\nmiddle records business events, such as sales, shipments or payments, as\nnumbers. Around it sit the tables that describe those events: which product,\nwhich store, which day, which customer. Drawn as a diagram, with a line from the\nmiddle table to each of the others, it looks like a star.\n\nThe table in the middle is the fact table, and the tables around it are\ndimension tables. The Kimball Group's description is short: \"Star schemas\ncharacteristically consist of fact tables linked to associated dimension\ntables\". The link is an ordinary key. Each dimension table has a single primary\nkey, and each fact row carries that key as a foreign key, one for every\ndimension that describes the event.\n\nThe split follows a distinction the Kimball Group draws between measurement and\ncontext. A dimensional model is built around the measurement events of a\nbusiness process: an item scanned at a till, an order shipped, a claim paid. The\nnumbers the event produces, such as the quantity and the amount, are the facts.\nEverything that says who, what, where, when, why and how is context, and it\nlives in the dimensions.\n\nThe two kinds of table have opposite shapes. At the most detailed level, a fact\ntable holds one row per event, with the numeric measures, a foreign key to every\ndimension, and sometimes a reference such as an invoice or receipt number. That\nnumber is all that is left of the document once its date, customer and store\nhave become dimensions, so it is stored on the fact row with no dimension table\nbehind it, and the Kimball Group calls it a degenerate dimension. A dimension\ntable, by contrast, is wide, flat and deliberately denormalised, with many\ndescriptive text columns. A product dimension repeats the brand, category and\ndepartment on every product row instead of splitting them out into tables of\ntheir own.\n\nA star schema is the relational form of a dimensional model, built from ordinary\ntables in an ordinary SQL database. The other form the Kimball Group describes\nis the OLAP cube, a multidimensional database holding the same attributes and\nfacts, queried in languages with more analytic power than SQL, such as MDX,\nwith XMLA providing a protocol for access. Cubes are often built from a star\nschema, as a last step before users see the data or as a layer of aggregates.\nThe modelling rules are the same for both, and the Kimball Group calls them\narchitecture-neutral: they apply to a Kimball-style data warehouse and to Bill\nInmon's hub-and-spoke Corporate Information Factory alike.\n\n## Why it matters\n\nThe shape makes analytical questions look alike. Pick the facts to add up, join\nthe fact table to the dimensions that describe them, filter on some dimension\ncolumns and group by others. The Kimball Group describes fact tables as the main\ntarget of calculations and dynamic aggregations, and dimension attributes as the\nmain source of query constraints, groupings and report labels. An analyst who\nhas learned that pattern once can write the next query against a new fact table\nwithout help, and a reporting tool can build it from a list of fields, because\nevery star has the same layout.\n\nReadability is the second reason. An operational database is designed to store\neach fact once and keep it consistent, so a product's category usually lives in\na separate lookup table, joined back by an id. That is the right design for the\nsystem that takes orders and the wrong one for someone looking for sales by\ncategory, who first has to work out which tables to join and in which order. A\nflat dimension puts every descriptive column in one place, written out in words.\nThe Kimball Group warns against the alternative, normalising a dimension's\nhierarchy into further tables, because business users find the result hard to\nunderstand and navigate.\n\nThe third reason is that a well-built star can answer questions nobody asked\nwhen it was designed. The grain of a fact table, the exact meaning of one row,\nis declared before any dimension or fact, and the Kimball Group recommends\nstarting at the atomic grain: the lowest level the business process captures. A\ntable with one row per receipt line can be summed by day, store, brand or any\ncombination of them. A table that keeps only daily totals per store can never be\nbroken down by product, however the question is phrased. In the Kimball Group's\nterms, atomic data withstands unpredictable queries, while rolled-up data\npresupposes the questions it will be asked.\n\nThe price is redundancy on purpose. The department name is repeated on every\nproduct row, and the load that builds the star has to keep those repetitions\nconsistent and decide what happens when a description changes. The star does not\nreplace the operational model either; it is built from it by a load process, and\nit is only as current as that load's last run.\n\n## What it looks like in practice\n\nA retailer wants sales by product category and month. The business process is\nthe till receipt, and the grain is declared as one row per receipt line. The\nproduct dimension is one flat table, the fact table holds a key for each\ndimension, the receipt number as a degenerate dimension and two measures.\n\n```sql\nCREATE TABLE dim_product (\n    product_key  bigint PRIMARY KEY,   -- surrogate key, owned by the warehouse\n    sku          text NOT NULL,        -- the code in the source system\n    product_name text NOT NULL,\n    brand        text NOT NULL,\n    category     text NOT NULL,\n    department   text NOT NULL\n);\n\nCREATE TABLE fact_sales (\n    date_key       integer NOT NULL REFERENCES dim_date,\n    store_key      integer NOT NULL REFERENCES dim_store,\n    product_key    bigint  NOT NULL REFERENCES dim_product,\n    receipt_number text    NOT NULL,   -- degenerate dimension\n    quantity       integer NOT NULL,\n    sales_amount   numeric(12, 2) NOT NULL\n);\n\nSELECT d.year_month, p.category, sum(f.sales_amount) AS sales\nFROM fact_sales AS f\nJOIN dim_date AS d USING (date_key)\nJOIN dim_product AS p USING (product_key)\nWHERE p.department = 'Grocery'\nGROUP BY d.year_month, p.category\nORDER BY d.year_month, p.category;\n```\n\nThe query has the shape every star query has: the fact table, one join per\ndimension, filters and groupings on dimension text, and a sum over a fact.\nAdding the store's region to the report is one more join and one more column in\nthe `GROUP BY`; the fact table does not change. The receipt number stays on the\nfact row, so the lines of one basket can still be counted together, but it gets\nno dimension table, because there is nothing more to say about it.\n\nA star is one answer to the promise of the\n[database design and modelling service](/services/database-design/): a structure\nthat matches how the business actually works, so the questions needed later can\nstill be asked. The operational model it is built from is the other half of that\nwork. In current work for NextMariner, the founder\n[modelled a maritime domain in 348 normalised tables](/portfolio/modeled-348-tables-across-34-postgres-schemas/)\nacross 34 PostgreSQL schemas, covering professionals, companies, ships, jobs and\nreviews. There, small stable lists such as statuses, types and categories became\nSMALLINT lookup tables, which keeps rows compact and joins cheap, and real\nforeign keys and constraints make integrity the database's job. That is the\nright shape for a system that writes rows one at a time and must stay correct. A\nstar built for reporting on top of such a system goes the other way: it turns\nthe codes back into words in flat dimensions, because its reader is a person\nrather than the application.\n\n## Where it goes wrong\n\n**The dimensions are normalised, and the star turns into a snowflake.**\nSplitting brand, category and department out of the product dimension into\ntables of their own looks tidy to anyone used to operational design. The Kimball\nGroup calls the result a snowflake and advises against it: business users find\nit hard to understand and navigate, and the extra joins can slow queries down,\nwhile a flat dimension holds exactly the same information. Keep each dimension\nas one wide table and let the load repeat the hierarchy on every row.\n\n**The grain is set to fit the first report.** A fact table of daily sales per\nstore answers the dashboard it was built for and nothing below it; the first\nquestion about a single product or basket needs a new load from the source. A\ntable that mixes daily totals with individual lines is worse, because any sum\nover it counts the same sale twice. Declare the grain first, start at the atomic\nlevel the process records, and give each grain a fact table of its own. Summary\ntables can then be added on top for speed, as separate tables.\n\n**The dimension attributes are the source system's codes.** Operational systems\nstore compact codes, and copying them straight into a dimension produces reports\nwhose row labels only the source system understands. The Kimball Group allows\ncodes as attributes but says the most useful attributes are verbose\ndescriptions, since those are what end up as labels on a report. Decode every\ncode into words during the load, and keep the code in a column beside the\ndescription for anyone who has to trace a row back to its source.\n\n**The fact table is shaped like a report.** It is tempting to design it from the\nspreadsheet the business already uses, with a column per month or a row per line\nof the management report. The Kimball Group is explicit that a fact table's\ndesign rests on the physical activity being measured, not on the reports that\nwill be drawn from it. Report layouts change; the till receipt does not. Model\nthe event, one row per occurrence at the declared grain, and let queries produce\nthe layouts.\n\n## Further reading\n\n- [Star Schemas and OLAP Cubes](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/star-schema-olap-cube/)\n  — the definition, facts and dimensions as measurement and context, and how\n  cubes relate to stars.\n- [Grain](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/grain/)\n  — declaring what one fact row means, and why the atomic grain comes first.\n- [Fact Table Structure](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/fact-table-structure/)\n  — numeric measures and foreign keys on one row per event, designed from the\n  activity rather than the report.\n- [Dimension Table Structure](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/dimension-table-structure/)\n  — wide, flat, denormalised tables whose descriptive attributes drive filters,\n  groupings and labels.\n- [Snowflaked Dimensions](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/snowflake-dimension/)\n  — why normalising a dimension's hierarchy makes it harder to use.\n- [Microsoft: Multidimensional model data access](https://learn.microsoft.com/en-us/analysis-services/multidimensional-models/mdx/multidimensional-model-data-access-analysis-services-multidimensional-data?view=sql-analysis-services-2025)\n  — MDX as a query and calculation language, and XMLA as the interface through\n  which a client can send an MDX statement.\n\n\u003chttps://engineer.company/glossary/star-schema/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"Business events in one fact table, flat dimension tables around it: how a star schema is built, why analysts can read it, and four ways it goes wrong.","formats":{"gemtext":"https://engineer.company/glossary/star-schema/index.gmi","gopher":"https://engineer.company/glossary/star-schema/gophermap","html":"https://engineer.company/glossary/star-schema/","json":"https://engineer.company/glossary/star-schema/index.json","markdown":"https://engineer.company/glossary/star-schema/index.md","pdf":"https://engineer.company/glossary/star-schema/index.pdf"},"kind":"page","language":"en","title":"What is a star schema?","url":"https://engineer.company/glossary/star-schema/","version":1}