Slowly Changing Dimension Designs: Temporal Tables

In a previous post I went through what a Slowly Changing Dimension is and how it can be a pain to all and sundry when designing a database. Before I move on to implementation in regard to code, I just wanted to touch on a few design thoughts in regard to the tables themselves as there is more than a couple of ways to store a slowly changing dimension. There’s no right or wrong, therefore these are just a few ideas to consider depending on what you feel suits you best or you’re most comfortable with.

Basic Table

This is the basic setup I’ll be using (single line formatting for compactness only):


We’re going to deal with the fact that Pear Computers has changed its name over the years and we need to know what it was on a Point In Time basis.

Temporal Tables

This is a new feature that was added in SQL Server 2016 which deals with this exact scenario of slowly changing dimensions alongside providing robust and thorough auditing. It’s incredibly powerful and easy to use. HOWEVER, it’s also quite a large topic and therefore I’ll go into more detail in some upcoming posts in which I’m going to focus exclusively on the Temporal Table in respect to construction, requirements, considerations, and performance.

Therefore, all I’m intending to do in this post is simply change my Company dimension into a Temporal Table for completeness on the Slowly Changing Dimension Designs topic. To do this we would change the Company table as follows:

This looks complicated and confusing at first glance but, once you’re used to Temporal Tables, this will gradually become second nature.

This then allows us to access the data in the following way (note the new syntax which is also why they’re getting their own set of blog posts soon – for the moment just follow along):

Summary (key points, not exhaustive)

• In-built into SQL Server
• Resiliant and accurate
o Good for auditing
o Point In Time
• Hidden to the average user
o No large code changes needed
• Performant
• Allows for different indexing per table

• New syntax for date based queries
• Not ideal if you wish to backdate changes or manually amend historical values

As I mentioned earlier, this is very much glossing over the Temporal Table as they warrant their own posts (and will get them in time)… but they are incredibly powerful if they can work for you. The only disadvantage is that they are strict auditing tables and although they are very good for Point In Time work and Slowly Changing Dimensions, they will not suit those who may need to backdate changes. For example, someone in Sales comes back to you and says “The system says that on 12th last month the company was known as “Bob’s Fish Shop” but actually that didn’t happen until the 13th”… that’s actually extremely hard to correct (as future posts will show) and therefore you might want to avoid these unless you’re sure they’re right for you.

Leave a Comment

Your email address will not be published. Required fields are marked *