Explain slowly changing dimensions and SCD Type 2.
Dimensions change over time: a customer moves city, a product changes category. A slowly changing dimension strategy decides how history is preserved.
- Type 1: overwrite the old value. Simple, but history is lost.
- Type 2: add a new row per change with valid_from and valid_to dates plus a current flag. This preserves full history and supports point-in-time reporting.
- Type 3: keep a previous_value column, limited to one prior state.
- Type 4 and 6: hybrids using history tables or current plus historical rows.
Type 2 is the most common for analytics. A fact row stores the dimension surrogate key valid when the event occurred, so joining facts to the correct historical version is automatic.
SELECT * FROM dim_customer
WHERE customer_id = 42 AND is_current = TRUE;
The downside is that the dimension grows and merge logic is more complex.