Defining Slowly Changing Dimensions
Defining Slowly Changing Dimensions
Product Organization
• Facts: transaction details Dimension
Dimension
such as invoice amount and
number of items sold.
• Dimensions: context to the facts Fact Table
such as customer information and
product information.
Customer Time
Dimension Dimension
6
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
7
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
2 Defining Slowly Changing Dimensions
Trend Analysis
A customer dimension can be analyzed for purchasing behavior as a function of income levels.
Income-based trends in purchasing behavior can be used to optimize marketing campaigns.
Change Tracking
Student records must be tracked over time to meet state and federal reporting mandates.
The reports are used to determine education spending.
Historical Reporting
Patients change their health-care provider. Health-care records from before the change can be
distinguished from health-care records after the change.
Archiving Records
Human resources departments keep histories of employee records, including job title and salary
history.
Defining Slowly Changing Dimensions 3
8
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Fact Table
Customer
Customer Time
Database Dimension Dimension
9
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Customer table in the DBMS has one row per customer.
Fact Table
Customer
Customer Time
Database Dimension Dimension
11
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Fact Table
Customer Overwrite
Customer Time
Database Dimension Dimension
12
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Fact Table
Idea Exchange
What are some reasons that you might have
to keep historical records for your data?
15
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
16
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
8 Defining Slowly Changing Dimensions
19
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
continued...
Primary and Foreign Keys
Primary and foreign keys are used to maintain referential integrity.
• Each dimension table in a star schema has a primary key.
20
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Defining Slowly Changing Dimensions 9
21
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
22
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
10 Defining Slowly Changing Dimensions
The SCD practice is mainly concerned with the relationship aspect of the primary and foreign keys
and not so much with the referential constraints.
Business Keys
Often, the business key in a dimension table can function as a primary key
in that table. Here are two examples:
• Customer_ID in the customer dimension table
• Product_ID in the product dimension table
23
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
24
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Defining Slowly Changing Dimensions 11
25
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
With Type 2 SCD, the business key will have duplicates, so it cannot function as a primary key.
There are several possible solutions to this problem.
12 Defining Slowly Changing Dimensions
PK 27
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Using an effective date, effective datetime, begin date, or begin datetime is a common practice for
SCD Type 2.
Defining Slowly Changing Dimensions 13
PK 28
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
PK
29
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
A surrogate key is a unique key that has a generated value. It is typically implemented as a uniformly
incrementing integer.
The current indicator is either 1, representing a current record, or 0, representing an old record.
31
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Lookup transformation is a generic lookup utility. It loads a target table with columns from a
source table and columns from any number of lookup tables.
32
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
16 Defining Slowly Changing Dimensions
a. Retained key
b. Surrogate key
c. There is not enough information to decide.
d. It contains neither a surrogate nor a retained key.
33
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.