Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CREATE TABLE dbo.Orders
(
[OrderId] INT NOT NULL PRIMARY KEY CLUSTERED
, [OrderValue] DECIMAL(19,4)
, [ValidFrom] DATETIME2 (2) GENERATED ALWAYS AS ROW START
, [ValidTo] DATETIME2 (2) GENERATED ALWAYS AS ROW END
, PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo)
)
WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.OrdersHistory));
GO
INSERT dbo.Orders ([OrderId], [OrderValue])
VALUES (1, 9.99), (2, 9.99);
GO
SELECT * FROM dbo.Orders;
GO
BEGIN TRAN
WAITFOR DELAY '00:00:30';
UPDATE dbo.Orders
SET [OrderValue] = [OrderValue] + 1;
COMMIT TRAN
GO
-- Run this in another query tab before the transaction above completes
SELECT GETUTCDATE() AS 'RunTime', * FROM dbo.Orders;
-----------------------------------------------------------------------
SELECT * FROM dbo.Orders
FOR SYSTEM_TIME AS OF 'PASTE THE RUNTIME VALUE FROM THE QUERY ABOVE';
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.