By Rohit Ray · Independent educational lesson · Explore this visual lab

Module 13 · Lesson 5 of 11Detailed study · about 22 min

SCD Types 0, 1, 2 and 3

Slowly changing dimensions describe how you keep—or deliberately discard—history when descriptive attributes change.

Understand the idea

Customer C1 moves from Pune to Mumbai on March 1. Type 1 reports Mumbai even when you join an old sale to the current record. Type 2 can report Pune for a January sale and Mumbai for an April sale. Neither is universally correct: the report’s question decides.

Key ideas in simple English
ConceptWhat it means
Type 0Keep the original value unchanged.
Type 1Overwrite the old value; no historical version remains.
Type 2Add a version with a validity interval.
Type 3Keep limited history in extra columns, such as previous city.

A concrete example

Customer C1 moves from Pune to Mumbai on March 1. Type 1 reports Mumbai even when you join an old sale to the current record. Type 2 can report Pune for a January sale and Mumbai for an April sale. Neither is universally correct: the report’s question decides.

Remember: Use half-open intervals so the new version owns the boundary and joins do not double-count.

Explain it step by step · full theory

Understand the concept

Customer C1 moves from Pune to Mumbai on March 1. Type 1 reports Mumbai even when you join an old sale to the current record. Type 2 can report Pune for a January sale and Mumbai for an April sale. Neither is universally correct: the report’s question decides.

Type 0 suits attributes that should remain original, such as an original acquisition channel. Type 3 might hold current_city and previous_city, but the next move overwrites the previous slot; it is not unlimited history.

Apply it in practice

For Type 2 we use VALID_FROM inclusive and VALID_TO exclusive. A sale exactly at March 1 belongs to the Mumbai row, not both rows. A NULL end means the latest open-ended version. IS_CURRENT alone cannot answer historical questions.

Business effective time is different from arrival time. A change effective February 1 might arrive in April. Keeping only the most recently arrived row loses the information needed to place that change between existing versions.

Words used in this lesson
Type 0
Keep the original value unchanged.
Type 1
Overwrite the old value; no historical version remains.
Type 2
Add a version with a validity interval.
Type 3
Keep limited history in extra columns, such as previous city.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 2

SCD Types 0, 1, 2 and 3

Type 0
Type 1
Type 3

Understand the flow

Slowly changing dimensions describe how you keep—or deliberately discard—history when descriptive attributes change.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Understand the flow

    Slowly changing dimensions describe how you keep—or deliberately discard—history when descriptive attributes change.

  2. Apply the contract

    Use half-open intervals so the new version owns the boundary and joins do not double-count.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Manual learning exercise. Production deployment needs source-specific contracts, access controls, orchestration and operational monitoring.

SCD Types 0, 1, 2 and 3 — SQL example

Definition: Slowly changing dimensions describe how you keep—or deliberately discard—history when descriptive attributes change.

When to use: Follow the isolated customer-history lab in lesson order.

Example: Only Mumbai. The boundary matches one interval because the end is exclusive.

SQL · example
WITH history(CITY,VALID_FROM,VALID_TO) AS (SELECT 'Pune','2026-01-01'::TIMESTAMP_NTZ,'2026-03-01'::TIMESTAMP_NTZ UNION ALL SELECT 'Mumbai','2026-03-01'::TIMESTAMP_NTZ,NULL::TIMESTAMP_NTZ) SELECT CITY FROM history WHERE '2026-03-01'::TIMESTAMP_NTZ>=VALID_FROM AND (VALID_TO IS NULL OR '2026-03-01'::TIMESTAMP_NTZ<VALID_TO);

What to expect and why

Only Mumbai. The boundary matches one interval because the end is exclusive.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Should both Type 2 versions match a fact exactly at their shared boundary?

Try it yourself

Explain with the example: Should both Type 2 versions match a fact exactly at their shared boundary?

Compare your reasoning

Use half-open intervals so the new version owns the boundary and joins do not double-count.

Official sources and curriculum

Module 13 · See module scope