learning-it by example

Back to the video

Slowly Changing Dimensions in SQL: Type 1 vs Type 2

The same seven sales put 105 pounds in the West with type 1, and 40 with type 2.

Video #110 ยท Data modelling

Steps in the video

  1. 0:00 Same sales, two histories: West sold 105, or 40
  2. 0:29 The idea
  3. 0:59 Setup
  4. 1:20 What the source sends
  5. 1:49 Two customer tables
  6. 2:19 Type one: overwrite
  7. 2:42 Type two: close the old row, add a new one
  8. 3:14 Facts find the right version
  9. 3:39 Run type one
  10. 5:11 What this does not show
  11. 5:35 Mistakes to avoid
  12. 6:10 My take and next steps
  13. 6:31 Recap

Files

  • run.py (58 lines)
  • scd.py (63 lines)
  • source.py (14 lines)

Download the code (zip)

Tested with

Python 3.12.15

What this does not show

Three made-up customers and seven sales in SQLite; type 1 and type 2 only, with no late-arriving changes and no speed measured.

Sources

Learning IT by Example.