Short answer: a system-versioned temporal table keeps the history of every row for you. Each row has two period columns, and when a row is updated or deleted, SQL Server moves the old version into a history table with the time it was valid. You then ask FOR SYSTEM_TIME AS OF '2026-03-01' and get the table exactly as it was at that moment. It works in SQL Server, Azure SQL Database and Azure SQL Managed Instance.
"What was this customer's credit limit when we approved the order?" is hard to answer from a table that only holds today. A temporal table answers it with one clause.
How does SQL Server keep the history?
- 1Current tableCredit limit 5,000, valid since 1 January
- 2UPDATEthe limit becomes 8,000 on 1 March
- 3History tablegets the 5,000 row, valid 1 January to 1 March
- 4Current tableholds 8,000, valid since 1 March
Nobody writes to the history table; the database does it in the same transaction as the change.
How do you create one and ask it?
CREATE TABLE dbo.Customer (
CustomerID int PRIMARY KEY,
Name nvarchar(100) NOT NULL,
CreditLimit decimal(18,2) NOT NULL,
ValidFrom datetime2 GENERATED ALWAYS AS ROW START NOT NULL,
ValidTo datetime2 GENERATED ALWAYS AS ROW END NOT NULL,
PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo)
)
WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.CustomerHistory));-- The table as it was on 15 February
SELECT CustomerID, CreditLimit
FROM dbo.Customer FOR SYSTEM_TIME AS OF '2026-02-15';
-- Every version of one customer
SELECT CreditLimit, ValidFrom, ValidTo
FROM dbo.Customer FOR SYSTEM_TIME ALL
WHERE CustomerID = 1042
ORDER BY ValidFrom;| Clause | Rows |
|---|---|
| AS OF t | the versions valid at time t |
| FROM a TO b | versions valid at any point between a and b, b not included |
| BETWEEN a AND b | like FROM, with b included |
| CONTAINED IN (a, b) | versions that started and ended inside the range |
| ALL | every version, current and history |
Temporal table or slowly changing dimension?
Both keep history, for different readers. A temporal table records when the database changed, with system times, and suits the operational side: audits, "as of" questions, undoing a bad update. A type 2 slowly changing dimension records when the business change took effect and gives each version a key a fact table can point at. A warehouse can build its type 2 dimension from a temporal source.
What goes wrong?
- History that grows for ever. Set a retention period (
HISTORY_RETENTION_PERIOD) on the table, or clean the history table on a schedule. - Times in UTC. The period columns are in UTC. Convert before comparing with local business dates.
- Bulk updates. Updating every row writes every old row to history. Plan big corrections with that in mind.
Where can you check this?
- Microsoft Learn: Temporal tables
- Microsoft Learn: Query data in a system-versioned temporal table
- Microsoft Learn: Manage retention of historical data in temporal tables
Where do you start?
Temporal tables are one of the specialised tables on DP-800, and the open course Upserts into Azure SQL builds a target table that could keep its history this way.