Created
July 7, 2016 14:07
-
-
Save James-DBA-Anderson/03a73277f08a3df72d658ba347715256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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