Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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.

The shortcut

Ask: "Should old facts be reported under the old value?" No, because it was an error or the history does not matter → Type 1. Yes, because history must stay as it was → Type 2.

Handling the station 17 moveStep 1 of 4
  1. Should June's rides stay in Old Town?

    Yes. Finance's past reports must not change, so use Type 2.

Drills

Answer fast — trust the rule.

quick drill

A rider's surname was misspelled at sign-up and is now corrected. Which type fits?

quick drill

Finance must report revenue by the zone each station belonged to at the time of the ride. Which type fits?

quick drill

After station 17 changes zone under Type 2, how many rows does dim_station hold for station_id 17?

quick drill

A ride on 15 June is loaded late, on 2 July. Which station key should it get?

Remember

  • When a dimension changes, choose: overwrite (Type 1) or keep history (Type 2).
  • Ask whether old facts should stay under the old value.
  • Type 2 needs surrogate keys, validity dates, and lookups by the fact's date.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainChoose the SCD type

A rider upgrades from a monthly plan to an annual plan on 1 August. Marketing wants to know how many rides were taken by monthly-plan riders each month last year. Explain which SCD type to use for plan_type in dim_rider, what the table looks like after the change, and how new rides get the right key.