DEV Community

Tarushi Vishnoi
Tarushi Vishnoi

Posted on

Understanding Slowly Changing Dimensions (SCDs)

Data changes over time, and handling these changes efficiently is crucial in Data Warehousing. This is where Slowly Changing Dimensions (SCDs) come into play! SCDs help us manage changes in dimensional data while preserving or overwriting history as needed.

Let's dive into SCD Type 1, Type 2, and Type 3, what they are, and when to use them.

SCD Type 1: Overwrite (No History)

  • The old data is replaced with the new data and no history is maintained.
  • Best for: When historical data is not required (e.g., fixing typos, updating contact information).

Example Scenario: A customer updates their email address. We don't need to track the previous one.

Data SCD-1 Result: The old value is overwritten, and no history is maintained.

SCD Type 2: Historical Tracking (New Row for Each Change)

  • A new record is inserted when data changes.
  • A surrogate key is used, and additional columns like Start_Date, End_Date, and Is_Active are added to track history.
  • Best for: Tracking historical changes over time (e.g., changes in customer address, job role).

Example Scenario: A customer moves from New York to Los Angeles. We want to keep a record of both addresses.

Data SCD-2 Result: The table now holds both the old and new addresses, maintaining history.

SCD Type 3: Limited History with Extra Columns

  • A limited history is kept in additional columns (e.g., Previous_Value).
  • Only tracks one or two changes.
  • Best for: When only the previous value needs to be retained (e.g., tracking a customer’s last known city).

Example Scenario: A customer moves from Chicago to Houston. We store the previous and current values in separate columns.

Data

SCD-3 Result: Only the most recent previous value is retained.

Managing Slowly Changing Dimensions effectively is key to maintaining accurate historical records in a data warehouse. Depending on your requirement, choose between SCD Type 1 (overwrite), SCD Type 2 (historical tracking), or SCD Type 3 (limited history).

Which SCD type do you use the most in your projects? Let’s discuss in the comments!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs