A Slowly Changing Dimension (SCD) is a dimension that stores and manages both current and historical data over time in a data warehouse. SCDs are dimensions that have data that changes slowly, rather than changing on a time-based, regular schedule. It is considered and implemented as one of the most critical ETL tasks in tracking the history of dimension records. There are three types of SCDs and you can use Warehouse Builder to define, deploy, and load all three types of SCDs.
· Type 1 SCDs: Overwriting
The Type 1 methodology overwrites old data with new data, and therefore does not track historical data. This is useful for making changes to dimension data.
Table 17: Type 1 SCDs Overwriting Example
|
N_PRODUCT_ SKEY |
V_PRODUCT_ NAME |
D_START_DATE |
D_END_DATE |
F_LATEST_RECORD_INDICATOR |
|
1 |
PL |
5/31/2010 |
12/31/9999 |
N |
In this example, N_PRODUCT_SKEY is the surrogate key column which is a unique key for each record in the dimension table. V_PRODUCT_NAME is the product name. D_START_DATE indicates the date from which this product record is valid. D_END_DATE indicates the date till which this product record is valid.
F_LATEST_RECORD_INDICATOR with value 'Y', which indicates this is the latest record in the dimension table for this product and 'N' indicates it is not. If the V_PRODUCT_NAME column is set as a Type 1 SCD column and if there is a change in the product name to 'Personal Loan' from 'PL' in the above example, in the next processing period, then when SCD is executed for the new processing period the record in the above example changes to:
Table 18: Type 1 SCDs - Overwriting1
|
N_PRODUCT_ SKEY |
V_PRODUCT_ NAME |
D_START_DATE |
D_END_DATE |
F_LATEST_RECORD_INDICATOR |
|
1 |
Personal Loan |
6/30/2010 |
12/31/9999 |
Y |
· Type 2 SCDs: Creating another dimension record
The Type 2 method tracks historical data by creating multiple records for a given natural key in the dimensional tables with separate surrogate keys. With Type 2, the historical changes in dimensional data are preserved. In the above example for the change in product name from 'PL' to 'Personal Loan' if history has to be preserved, then the V_PRODUCT_NAME column has to be set as Type 2 when SCD is processed for the processing period and the change inserts a new record as shown in the following example:
Table 19: Type 2 SCDs – Create Another Dimention Record
|
N_PRODUCT_ SKEY |
V_PRODUCT_ NAME |
D_START_DATE |
D_END_DATE |
F_LATEST_RECORD_INDICATOR |
|
1 |
PL |
6/30/2010 |
12/31/9999 |
N |
|
2 |
Personal Loan |
6/30/2010 |
12/31/9999 |
Y |
A new record is inserted to the product dimension table with the new product name. The latest record indicator for this is set as 'Y', indicating that this is the latest record for the personal loan product. The same flag for the earlier record was set to 'N'.
· Type 3 SCDs - Creating a current value field
A Type 3 SCD stores two versions of values for certain selected level attributes. Each record stores the previous value and the current value of the selected attribute.
When the value of any of the selected attributes changes, the current value is stored as the old value and the new value becomes the current value.