Temporal tables
Temporal tables store data and all changes so that data from a previous point in time can be retrieved. SQL Server 2016 added support for temporal tables. Temporal tables are also known as system-versioned temporal tables.
Each temporal table is paired with a history table so that normal queries pull data from the table as normal, but historical queries can be constructed that pull data from the history table. The following diagram illustrates this:
Figure 10.8: Temporal table structure
Why temporal tables?
Some use cases of temporal tables are as follows:
- Audit trail – Keep a full log of what changed in the table.
- Accidental changes – Easily restore data that was mistakenly changed or deleted.
- Historical reports – Be able to report on how data changes over time.
- Detect changes – Compare current and previous data more easily.
Temporal table example
When creating temporal tables...