SYSTEM_TIME
SYSTEM_TIME is a temporal clause in SQL that allows you to query data as it was at a certain point in time or throughout a specific time period. It is used with temporal tables to keep track of historical changes to the data.
Example
SELECT *FROM Sales.OrdersFOR SYSTEM_TIME AS OF '2021-05-01T12:34:56.1234567'
Output
OrderID | CustomerID | ProductID | OrderDate | Quantity--------|------------|-----------|----------------------------|----------10248 | VINET | 11 | 2021-04-30T13:34:56.1234567| 1210249 | TOMSP | 42 | 2021-04-30T14:34:56.1234567| 10
Explanation
The SYSTEM_TIME
temporal table function with AS OF
is used to query the data as it existed at a specific point in time. In the example, the query is returning the data from the Sales.Orders
temporal table as it existed on ‘2021-05-01T12:34:56.1234567’.