The types at a glance
| Type | Behavior | History kept | Typical use |
|---|---|---|---|
| 0 | Retain the original value; never update | The first value only | First order date, original acquisition channel |
| 1 | Overwrite in place | None | Corrections, descriptions, attributes nobody analyzes historically (all of dim_product in the sample) |
| 2 | Expire the current row, insert a new version with a new surrogate key | Full | Customer region and segment in dim_customer |
| 3 | Add a "previous value" column | One prior value | A one-off reorganization: region and region_prior |
| 4 | Split fast-changing attributes into a mini-dimension (Kimball), or keep history in a separate table (common usage) | Full, in a separate table | Customer credit band or demographic bands that change monthly |
| 6 | Type 2 rows plus a Type 1 "current" column overwritten on every version (1 + 2 + 3) | Full, with as-is available | region (as-was) beside current_region (as-is) |
Two more appear in Kimball's later writing. Type 5 is a Type 4 mini-dimension plus a Type 1 outrigger on the base dimension that points at the current mini-dimension row. Type 7 puts both the surrogate key and the durable business key on the fact, so the model can join to all versions for as-was reporting and to a current-rows view for as-is. Both are useful in specific cases and rarely the first thing you need.
Note that "Type 4" means different things to different authors. Say which one you mean in your design notes.
Which ones you actually need
Types 1 and 2 cover the vast majority of real dimensions. The real design work is deciding, attribute by attribute, which behavior applies. dim_customer is called "Type 2" in the sample because region and segment are tracked, but a fix to a misspelled customer_name should still be a Type 1 update applied across all versions. Otherwise a typo correction creates a fake history event.
Track history only for an attribute where someone can name the question that needs it ("sales by the region the customer was in at the time"). Every tracked attribute multiplies rows and makes change detection noisier.
Decide up front whether reports default to as-was (the attribute value at the time of the fact, which Type 2 gives you through the fact's surrogate key) or as-is (today's value applied to all history). Most sales reporting wants as-was for territory and as-is for names and hierarchies. Type 6 columns are the cheapest way to offer both in one dimension table; label them clearly in the semantic model so users know which one they are slicing by.
Change detection with a hash diff
Comparing every tracked column one by one is verbose and slow. Instead, compute a hash over the tracked attributes in staging and compare one column. Keep separate hashes for Type 2 attributes and Type 1 attributes so each change takes the right path.
-- T-SQL (Fabric Warehouse): staging snapshot of silver.customer with a Type 2 hash
SELECT
customer_id,
customer_name,
region,
segment,
HASHBYTES('SHA2_256', CONCAT_WS('|',
COALESCE(region, '~'),
COALESCE(segment, '~'))) AS row_hash
FROM silver.customer;
-- Spark SQL equivalent
SELECT customer_id, customer_name, region, segment,
sha2(concat_ws('|', coalesce(region, '~'), coalesce(segment, '~')), 256) AS row_hash
FROM silver.customer;
CONCAT_WS skips NULLs, so without the COALESCE sentinel the values ('East', NULL) and (NULL, 'East') hash identically. Also compute the hash in one engine only. Spark and T-SQL format dates, decimals and floats differently as strings, so a hash written by a notebook will not match one computed in the Warehouse, and every row will look changed.
Loading Type 2
The load has the same five steps in any engine: stage the silver snapshot with its hash, find current rows whose hash differs, expire them, insert new versions for changed and brand-new business keys, then apply Type 1 updates across all versions.
The two-step pattern below works in Fabric Warehouse today and is easy to read. The trick is in the insert: after the expire step, a changed customer no longer has a current row, so the same "no current row" test picks up both new and changed keys.
DECLARE @load_ts datetime2(6) = SYSUTCDATETIME();
DECLARE @max_key bigint = (SELECT COALESCE(MAX(customer_key), 0) FROM gold.dim_customer);
BEGIN TRANSACTION;
-- 1. Expire current versions whose tracked attributes changed
UPDATE d
SET valid_to = @load_ts,
is_current = 0
FROM gold.dim_customer AS d
JOIN stg.customer AS s ON s.customer_id = d.customer_id
WHERE d.is_current = 1
AND d.row_hash <> s.row_hash;
-- 2. Insert a version for every key with no current row (new or just expired)
INSERT INTO gold.dim_customer
(customer_key, customer_id, customer_name, region, segment, current_region,
row_hash, valid_from, valid_to, is_current)
SELECT @max_key + ROW_NUMBER() OVER (ORDER BY s.customer_id),
s.customer_id, s.customer_name, s.region, s.segment, s.region,
s.row_hash, @load_ts, '9999-12-31', 1
FROM stg.customer AS s
LEFT JOIN gold.dim_customer AS d
ON d.customer_id = s.customer_id AND d.is_current = 1
WHERE d.customer_id IS NULL;
-- 3. Type 1 and Type 6 attributes: overwrite on every version
UPDATE d
SET customer_name = s.customer_name,
current_region = s.region
FROM gold.dim_customer AS d
JOIN stg.customer AS s ON s.customer_id = d.customer_id
WHERE d.customer_name <> s.customer_name
OR d.current_region <> s.region;
COMMIT TRANSACTION;
In a lakehouse, Delta's MERGE INTO can do expire and insert in one statement with the "staged updates" trick: union the changed rows a second time with a NULL merge key so they fall through to the insert branch.
-- Spark SQL on Delta. stg_customer carries a precomputed new_key.
MERGE INTO gold.dim_customer AS t
USING (
SELECT s.customer_id AS merge_key, s.* FROM stg_customer AS s
UNION ALL
SELECT NULL AS merge_key, s.*
FROM stg_customer AS s
JOIN gold.dim_customer AS d
ON d.customer_id = s.customer_id AND d.is_current = true AND d.row_hash <> s.row_hash
) AS u
ON t.customer_id = u.merge_key AND t.is_current = true
WHEN MATCHED AND t.row_hash <> u.row_hash THEN
UPDATE SET t.is_current = false, t.valid_to = current_timestamp()
WHEN NOT MATCHED THEN
INSERT (customer_key, customer_id, customer_name, region, segment, current_region,
row_hash, valid_from, valid_to, is_current)
VALUES (u.new_key, u.customer_id, u.customer_name, u.region, u.segment, u.region,
u.row_hash, current_timestamp(), timestamp'9999-12-31 00:00:00', true);
Fabric Warehouse gained a T-SQL MERGE statement relatively recently (it arrived in preview during 2025). Check its status and documented limitations in your tenant before standardizing on it. The two-step UPDATE plus INSERT inside an explicit transaction is atomic, works everywhere, and is easier to debug a step at a time. In a Lakehouse, Delta MERGE INTO from Spark is mature; just remember the SQL analytics endpoint is read-only, so SCD loads there must run in Spark.
Late-arriving dimensions and inferred members
Sometimes a fact arrives before its dimension row: an order references a customer the CRM has not synced yet. Mapping it to -1 keeps totals right but loses the link forever. An inferred member keeps it: insert a placeholder dimension row with the business key, "Unknown" attributes and an is_inferred flag, and point the fact at it.
INSERT INTO gold.dim_customer
(customer_key, customer_id, customer_name, region, segment, current_region,
row_hash, valid_from, valid_to, is_current, is_inferred)
SELECT @max_key + ROW_NUMBER() OVER (ORDER BY x.customer_id),
x.customer_id, 'Unknown', 'Unknown', 'Unknown', 'Unknown',
NULL, '1900-01-01', '9999-12-31', 1, 1
FROM (SELECT DISTINCT customer_id FROM silver.sales_order_line) AS x
LEFT JOIN gold.dim_customer AS d ON d.customer_id = x.customer_id
WHERE d.customer_id IS NULL;
When the real customer arrives, update the inferred row in place (Type 1 style) and clear the flag, rather than expiring it and creating a version. The placeholder never represented a real state of the customer, so it should not appear as history.
The opposite case, a late-arriving fact (an order from last month loaded today), is handled by the point-in-time lookup below: it finds the version that was valid on the order date, not today's.
Point-in-time lookups for facts
Facts join to Type 2 dimensions on the business key and the effective date range, with valid_to treated as exclusive:
LEFT JOIN gold.dim_customer AS c
ON c.customer_id = s.customer_id
AND s.order_date >= c.valid_from
AND s.order_date < c.valid_to
Three details make this reliable. Give each business key's first version a valid_from of 1900-01-01, so historical facts loaded before the dimension existed still find a row. Use the source system's change timestamp for valid_from when it has a trustworthy one; the load timestamp is a fallback that makes history only as precise as your schedule. And never let ranges for one business key overlap or leave gaps; add a test for it.
Should SCD2 history live in the lake (Delta MERGE, maybe driven by Change Data Feed) or in the warehouse (T-SQL transactions)? Both work; the deciding factor is which engine owns the rest of gold. See Open questions.
The Star schema explorer shows dim_customer with its surrogate key, business key and validity columns, and how fact_sales points at a specific version.