Lab: SCDs

Slowly Changing Dimensions ..

The demonstration illustrates the key concepts and workflows for dealing with Slowly Changing Dimensions.

In this Lab, you are going to create a dimension table DIM_SCD, which will have:

• a technical key field

• a version field

• a date from and date to fields

• an Id field

• a name field

The technical key will become the primary key for the dimension table.

The version field sets the record version (increments) on an update or insert.

Create the Table in MySQL sampledata database.

  1. In your DB management tool, execute the following statement.

CREATE TABLE `DIM_SCD` (
  `TK` bigint(10) NOT NULL,
  `version` int(11) DEFAULT '0',
  `id` int(11) DEFAULT '0',
  `city` tinytext,
  `date_from` datetime DEFAULT NULL,
  `date_to` datetime DEFAULT NULL,
  `last_update` datetime DEFAULT NULL,
  PRIMARY KEY (`TK`),
  KEY `idx_DIM_SCD_lookup` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

This step is rarely used for lookups as specific steps exists; however, it does illustrate the database process of how referential integrity is maintained.

  1. Add ‘London’ to the Data Grid.

To initially configure the fields set the step to Update mode.

Once completed remember to reset to lookup mode.

  1. Ensure that the Dimension Lookup / Update is set to: Lookup Mode.

Sets the step to Update Mode with lookup keys: id

There’s no point adding the LAST_UPDATE field as we're dealing with Type 1 changes.

  1. Click on the Fields tab.


RUN the Transformation

  1. Click the Run button in the Canvas Toolbar.

  2. Click on the Dimension lookup/update step and Preview the data.

Why does London have a TK 0 and a value of NULL?

To maintain referential integrity, the record is assigned a TK 0, and as it doesn’t exist in the database, the value returned is NULL. As this is a lookup, no record is written to the database table.

Last updated