|
Dimensions don't change in predicable ways. Individual customers and products evolve slowly and episodically. Some of the changes are true physical changes. Customers change their addresses because they move. A product is manufactured with different packaging. Other changes are actually corrections of mistakes in the data. And finally, some changes are changes in how we label a product or customer and are more a matter of opinion than physical reality. We call these variations Slowly Changing Dimension (SCD).
The 3 fundamental choices for handling the slowly changing dimension are:- Overwrite the changed attribute, thereby destroying previous history.e.g. Useful when correcting an error.
- Issue a new record for the customer, keeping the customer natural key, but creating a new surrogate primary key.
- Create an additional field in the existing customer record, and store the old value of the attribute in the additional field. Overwrite the original attribute field.
- Type 1 SCD is an overwrite of a dimensional attribute. History is definitely lost. We overwrite when we are correcting an error in the data or when we truly don't want to save history.
- A Type 2 SCD creates a new dimension record and requires a generalized or surrogate key for the dimension. We create surrogate keys when a true physical change occurs in a dimension entity at a specific point in time, such as the customer address change or the product packing change. We often add a timestamp and a reason code in the dimension record to precisely describe the change.
The Type 2 SCD records changes of values of dimensional entity attributes over time. The technique requires adding a new row to the dimension each time there's a change in the value of an attribute (or group of attributes) and assigning a unique surrogate key to the new row.
- A Type 3 SCD adds a new field in the dimension record but does not create a new record. We might change the designation of the customer's sales territory because we redraw the sales territory map, or we arbitrarily change the category of the product from confectionary to candy. In both cases, we augment the original dimension attribute with an "old" attribute so we can switch between these alternate realities.
|