Temporal tables, also known as system-versioned temporal tables, are a feature in SQL Server that provide built-in support for tracking historical data changes. They automatically keep a full history of data changes and allow you to query data as it was at any point in time.
Current Table: The main table that holds the current data.
History Table: A separate table that stores the historical versions of the data.
Here' how you can create a temporal table:
Create the Main Table and History Table:
Enable System-Versioning: If you have an existing table, you can enable system-versioning like this:
You can query temporal tables to retrieve data at a specific point in time or over a period of time.
As Of Specific Point in Time:
Between Two Points in Time:
From Beginning to a Point in Time:
Disable System-Versioning: Temporarily disable system-versioning if needed.
Delete Historical Data: Purge historical data to manage storage.
Data Auditing: Automatically maintain historical data for auditing purposes.
Time Travel Queries: Easily query data as it was at any point in time.
Simplified Data Management: Built-in support for maintaining and querying historical data.
Temporal tables are powerful for scenarios requiring historical data tracking and auditing. If you have specific use cases or need more examples, feel free to let me know!