Skip to the workspace
Pebellslearn by building
Database Fundamentals  ›  Capstone Project

Slowly Changing Dimensions

Slowly Changing Dimension - SCD 12 minWhen a dimension attribute changes, Type 1 overwrites it so all history shows the new value, while Type 2 adds a new dated row with a new surrogate key so past facts keep the old value.

data engineer / Slowly Changing Dimensions

Explore each scene at your own pace.

01 · The rule

The rule

Slowly Changing Dimensions

On 1 July PedalCity moved station 17 from the "Old Town" zone to the new "Riverside" zone. Finance then asked, "What was Old Town's revenue in June?" and the answer had dropped by a fifth overnight. Nobody had deleted anything. The dimension had simply been overwritten. Dimensions change slowly, and you must decide how the model remembers those changes.

The rule

When a dimension changes, choose: overwrite history (Type 1) or keep it (Type 2).

Type 1: overwrite. Update the attribute in place. Every past fact now appears under the new value.

UPDATE dim_station SET zone = 'Riverside' WHERE station_id = 17;

This is right for corrections. If a rider's name was misspelled, nobody wants the typo preserved.

Type 2: add a new row. Close the old row and insert a new one, each with its own surrogate key (a warehouse-made ID) and a validity range:

station_key station_id zone valid_from valid_to is_current
301 17 Old Town 2024-03-01 2026-06-30 false
588 17 Riverside 2026-07-01 9999-12-31 true

Rides from June still point to key 301, so June's revenue stays in Old Town. Rides from July onward point to key 588. The business ID station_id stays 17 in both rows, which is why the surrogate key is needed.

When loading a ride, look up the dimension row that was valid on the ride's date, not simply the current one.

Two other types are worth knowing by name. Type 0 never changes the value, such as a rider's original sign-up date. Type 3 keeps a previous_zone column next to zone, which remembers just one earlier value.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.