SCD Type 4
A slowly changing dimension technique that moves a group of rapidly changing attributes out of a large dimension into a separate mini-dimension, with the fact table holding a key to each. Other references use the same name for keeping current rows in one table and past versions in a history table.
Also: slowly changing dimension type 4 · Type 4 SCD · mini-dimension
On this page · 7 sections
- Category
- Data modeling
- Also known as
- slowly changing dimension type 4, Type 4 SCD, mini-dimension
- Goes deeper in
- Data Modeling
SCD Type 4 has two meanings in circulation, so check which one a document intends. In the Kimball Group's own material, Type 4 is titled Add Mini-Dimension: attributes that change often are taken out of a very large dimension and placed in a small table of their own. In other references, including Wikipedia's article on slowly changing dimensions, Type 4 is instead a history table that sits beside a table of current rows.
The mini-dimension solves a size problem. A customer dimension with millions of rows and attributes such as age band and income band would gain a row every time one of them changed if each change were tracked as a Type 2 row. Instead, the mini-dimension holds one row per combination of band values, and each fact row stores two keys: the customer, and the profile in effect at that moment.
The history-table reading keeps the main dimension at one row per entity, overwritten on change, and records the changes in a second table, each with its date. The two designs answer different needs. This page follows Kimball's numbering: the Kimball Group gave the mini-dimension the Type 4 label in the third edition of The Data Warehouse Toolkit, published in 2013.
create table dim_customer_profiles ( -- the mini-dimension
customer_profile_key integer primary key,
age_band varchar(20) not null,
income_band varchar(20) not null
);
create table fct_orders (
order_id integer primary key,
date_key integer not null,
customer_key integer not null, -- base dimension: name, address
customer_profile_key integer not null, -- profile in effect at the order
order_amount numeric(10, 2) not null
);
select
c.customer_name,
p.income_band,
count(*) as orders,
sum(f.order_amount) as revenue
from fct_orders f
join dim_customers c on c.customer_key = f.customer_key
join dim_customer_profiles p
on p.customer_profile_key = f.customer_profile_key
group by c.customer_name, p.income_band
order by c.customer_name, p.income_band;It keeps a huge dimension stable. Volatile attributes stop generating new rows in the base table, and analysis by those attributes joins the fact table to a small mini-dimension instead of to millions of customer rows.
The history is recorded only where facts exist. A fact row captures the profile at the time of its event, so a change that falls between two events leaves no trace. If every change must be kept, a separate history structure is still needed.
- Storing continuous values in the mini-dimension. Exact income or exact age gives nearly one row per customer; the attributes must be banded so the number of combinations stays small.
- Assuming a colleague means the same Type 4. Agree on mini-dimension or history table before reviewing a design that uses the label.
- Expecting to read a customer's current profile from the base dimension. In plain Type 4 it is reachable only through the fact table; Kimball's Type 5 adds a current profile key to the base dimension for this reason.
- What is a mini-dimension?
- A small dimension table made from a group of attributes split off from a larger dimension, usually ones that change often or are queried heavily. It has one row per combination of attribute values, with its own key, and the values are banded into ranges to keep the row count low. The fact table stores the mini-dimension key next to the main dimension key.
- What is the difference between SCD Type 2 and Type 4?
- Type 2 records a change by adding a row to the dimension itself, so the dimension grows with every change. Type 4, in Kimball's sense, takes the changing attributes out of the dimension and lets the fact table record which combination applied at each event. Type 2 suits attributes that change occasionally; the mini-dimension suits attributes that change often in a very large table.
- Is SCD Type 4 a history table?
- In some references, including Wikipedia's article on slowly changing dimensions, yes: the current rows live in one table and a record of the changes in a separate history table. The Kimball Group defines Type 4 as adding a mini-dimension. Both designs are in real use, so the safest habit is to name the structure and not only the number.
