Snowflake schema
A dimensional model in which dimension tables are normalized: each level of a hierarchy, such as city and region, is moved into its own table and linked by a key. The name comes from the branching shape of the diagram and has nothing to do with the Snowflake data platform.
Also: snowflaked dimension · snowflaking · snowflake model · snowflake data model
On this page · 7 sections
- Category
- Data modeling
- Also known as
- snowflaked dimension, snowflaking, snowflake model, snowflake data model
- Goes deeper in
- Data Modeling
A snowflake schema stores a dimension as a chain of tables instead of one. A store dimension that would otherwise carry the city and region on every row keeps only a city key. The city table holds the city name and a region key, and the region table holds the region name. Drawn out, the tables branch away from the fact table like the arms of a snowflake.
The technique is normalization applied to dimensions: each value in a hierarchy is stored once and referenced by key. Ralph Kimball's term is a snowflaked dimension, and his guidance is to avoid it. A flattened dimension, the kind a star schema uses, holds exactly the same information in one table, is easier for business users to browse, and needs one join where the snowflake needs one per level.
The name is easily confused with Snowflake, the cloud data platform. They are unrelated: a snowflake schema is a table design that can be built in any relational database, and Snowflake the product can hold any design. Snowflaking still has uses, such as a hierarchy that several dimensions share or one that is maintained separately as reference data.
-- Snowflaked: the store dimension is three tables.
select
r.region_name,
sum(f.sales_amount) as sales
from fct_sales f
join dim_stores s on s.store_key = f.store_key
join dim_cities c on c.city_key = s.city_key
join dim_regions r on r.region_key = c.region_key
group by r.region_name
order by r.region_name;
-- Flattened: the same information presented as one dimension.
create view dim_stores_flat as
select
s.store_key,
s.store_name,
c.city_name,
r.region_name
from dim_stores s
join dim_cities c on c.city_key = s.city_key
join dim_regions r on r.region_key = c.region_key;
select
d.region_name,
sum(f.sales_amount) as sales
from fct_sales f
join dim_stores_flat d on d.store_key = f.store_key
group by d.region_name
order by d.region_name;Source systems arrive normalized, so a warehouse that copies their structure ends up snowflaked without anyone deciding it. Knowing the term lets you see it as a choice: every extra level is another join in every query that needs that attribute, and another relationship for a BI tool to resolve.
It also matters when reading requirements. A request to model data in Snowflake is about the platform, and a request for a snowflake model is about table design. Confirming which one is meant takes a minute and avoids building the wrong thing.
- Snowflaking to save storage. Dimension tables are small next to fact tables, so removing repeated region names from the store rows saves little and costs a join on every query.
- Assuming the design is tied to the Snowflake platform, or that the platform requires it.
- Exposing the normalized tables directly to report builders. If the hierarchy must be stored snowflaked, publish a flattened view on top so each dimension still appears as one table.
- Is a snowflake schema related to Snowflake the data warehouse?
- No. The snowflake schema is a modeling pattern named for the shape of its diagram, and it can be built in PostgreSQL, BigQuery, SQL Server, or any other relational database. Snowflake is a company and a cloud data platform. Tables in Snowflake can be organized as a star, a snowflake, or anything else.
- What is an example of a snowflake schema?
- A sales fact table joined to a store table, which joins to a city table, which joins to a region table. Each level of the location hierarchy is its own table. The same pattern appears with product, subcategory, and category, or with employee, team, and department. A query by region has to pass through every table in the chain.
- When should you use a snowflake schema?
- Normalize a dimension when one of its hierarchies is shared by several dimensions, or when it is maintained separately as reference data and loading it once is simpler than copying it into each dimension. Otherwise keep each dimension in one flat table, which is the Kimball Group's recommendation and the easier design to query.
