Thursday, 2 June 2011

SCD – Slowly Changing Dimensions

SCD – Slowly Changing Dimensions
Implementing SCD’s is common concern in Data Warehouse design. Let me brief about different types of SCD’s first then we can step in to SCD’s design.
Dimensions that change over time are called Slowly Changing Dimensions. For instance, a product price changes over time; People change their names for some reason; Country and State names may change over time. These are a few examples of Slowly Changing Dimensions since some changes are happening to them over a period of time.
Everybody knows that ‘Slowly Changing Dimensions’ is the acronym for SCD.
We have 4 types of SCD’s in Data Warehouse
Let’s say I have a customer dimension with these columns mainly
 (Customer Id, Customer First Name, Customer Last Name, Customer Country)
Customer
Id
Customer First Name
Customer Last Name
Customer Country
1
Sudheer
Sharma
India

Now, this guy moved to US. In source the country name has been changed to US, we need to update that in our target dimension to reflect this change.
SCD Type 1: The new incoming record (changed/modified data set) replaces the existing old record in target.
Customer
Id
Customer First Name
Customer Last Name
Customer Country
1
Sudheer
Sharma
US

Old value (India) is overwritten by the new value (US) and there is no way to find out the old version of data. It holds only the current version of data.




SCD Type 2: In this case, an additional record is added into the customer dimension. The beauty of this approach is it will maintain two versions, you will find two records the older version and the current version. In other words it maintains history. Again we can implement Type 2 in following methods
  1. Versioning
  2. Effective Dates
  3. By setting Current Flag values/Record Indicators.
Method 1: Versioning
Customer Id
Customer First Name
Customer
Last Name
Customer Country
Effective Year
Version
1
Sudheer
Sharma
India
2008
0
1
Sudheer
Sharma
US
2009
1

Method 2: Effective Dates
Customer Id
Customer
First Name
Customer Last Name
Customer Country
Effective
Start Date
Effective EndDate
1
Sudheer
Sharma
India
01/01/2008
12/31/2008
1
Sudheer
Sharma
US
01/01/2009
tilldate

Method 3: Effective Dates & Current Record Indicators
Customer Id
Customer
First Name
Customer
Last Name
Customer Country
Effective
Start Date
Effective
End Date
Current Record IND
1
Sudheer
Sharma
India
01/01/2008
12/31/2008
N
1
Sudheer
Sharma
US
01/01/2009
tilldate
Y

SCD Type 3: In this approach, only the information about a previous value of a dimension is written into the database. An ‘old ‘or ‘previous’ column is created which stores the immediate previous attribute.
Product
ID
Product
Name
Current
Year
Current
Price
Previous
Year
Previous
Price
1
Close-up
2008
50.00
2007
45.00

The problem with this approach is over years, if the product price continuously changes, then the complete history may not be stored, only the latest change will be stored. For example, in year 2009, if the product price changes to 60, then we would not be able to see the complete history of 2007 prices, since the old values would have been updated with 2008 information.
SCD Type 4: In this approach, one table hold current data and another table keeps historical data for each dimension.
Customer Dimension
Customer
Id
Customer
First Name
Customer
Last Name
Customer
Country
1
Sudheer
Sharma
US

Customer History Table
Customer
Id
Customer
First Name
Customer
Last Name
Customer
Country
Effective Year
1
Sudheer
Sharma
India
2008


11 comments:

  1. Thank you so much for this blog. Long days I have been confused by SCD's where I got much clear with the concepts the way you explained in this ! Keep up the good work which helps lot of people ! Thanks !

    ReplyDelete
  2. Thank you for this blog,But i want to know...How will be implement SCD-4,Can u give an idea about this.....

    ReplyDelete
    Replies
    1. Using Trigger.
      When ever any update on base table, record with old value will insert in Audit table.

      Delete
  3. Thanks for your valuable efforts....

    ReplyDelete
  4. Thanks a lot....

    ReplyDelete
  5. Thanks very much....now i got a cleat idea about SCD

    ReplyDelete
  6. Best Informatica Training by TOP Industry Experts in Delhi/NCR with 100% Job Oriented & Placement Record.

    Free 1st Demo Class, Fresh Batch Start from Nov-2014 Call to Book Your Seat Now : 08447037614/09910840204, info@ambrot.com

    ReplyDelete
  7. Hamsini Technologies is Best Informatica Training by TOP Industry Experts in Hyderabad with 100% Job Oriented & Placement Record.

    Free 1st Demo Class,
    Contact us : info@hamsinitechnologies.com
    Informatica Online training

    ReplyDelete
  8. Good Article on SCD Types in Informatica

    ReplyDelete