# Type 2 SCDs

Type 2 Slowly Changing Dimension (SCD) is a data warehousing method used to track changes in data over time by preserving the change history. You can view the historical data for each record and their corresponding time range when it was valid.

### 1. Understanding Type 2 SCDs

* Whenever an entity's data in any dimension changes, a new row is created instead of overwriting the old ones.
* Each new row includes the updated information along with the start date and end date that indicate the validity period of the updated information.
* There is an additional flag column that indicates the record that is currently active. This column can be of the checkbox type or a simple true/false or 0/1 column.
* There can be one or more timestamp columns in addition to the start date to signify when a new record was actually created or when the change was made effective.

This approach allows us to analyze the historical data and understand how the information has evolved over time.

### 2. Example for Type 2 SCDs

Let us consider an employee database where the employees' details, such as salary, incentive, job role, etc., can slowly change over time.

With SCDs, whenever there is a change, a new row with the updated details is created instead of overwriting the old one. This new row includes an effective start date that indicates when it was updated or when the new details became live.

Meanwhile, the old row will have an end date marking when it was last valid. Likewise, every change made to an employee is tracked through a series of rows, each with its respective start and end dates.

Find below the database where SCDs are in place:

<table data-full-width="false"><thead><tr><th width="155" align="center">ID (Surrogate Key)</th><th width="129" align="center">Emp.ID (Business Key)</th><th width="119" align="center">Employee Name</th><th width="91" data-type="number">Salary</th><th width="147">RowValidFrom</th><th width="142">RowValidTo</th></tr></thead><tbody><tr><td align="center">1</td><td align="center"><mark style="color:green;"><strong>C501</strong></mark></td><td align="center"><mark style="color:green;"><strong>John S</strong></mark></td><td>70000</td><td>20-10-2023</td><td>23-10-2024</td></tr><tr><td align="center">56</td><td align="center">C002</td><td align="center">Alan B</td><td>75000</td><td>01-01-2024</td><td>31-12-2025</td></tr><tr><td align="center">234</td><td align="center"><mark style="color:green;"><strong>C501</strong></mark></td><td align="center"><mark style="color:green;"><strong>John S</strong></mark></td><td>80000</td><td>24-10-2024</td><td>31-12-2025</td></tr><tr><td align="center">235</td><td align="center">C988</td><td align="center">Lily S</td><td>65000</td><td>21-10-2024</td><td>31-12-2025</td></tr></tbody></table>

One table row represents an entity's attributes for a defined timespan. The whole lifespan of one business entity can be inferred from a list of such rows.

In the next section, we will discuss how to configure a database that can support SCDs and how you can assign the appropriate keys in PowerTable.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powertable.com/explore-powertable/type-2-scds.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
