Temporal Tables Flashcards

1
Q

What is the syntax for creating a Temporal Table?

A

CREATE TABLE dbo.TableName
(
PrimKeyField int PRIMARY KEY
, [ValidFrom] datetime2 GENERATED ALWAYS AS ROW START
, [ValidTo] datetime2 GENERATED ALWAYS AS ROW END
, PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo)
)
WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.TableHistory));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the necessary elements for a Temporal Table?

A

Primary Key
valid from column (datetime2) with GENERATED ALWAYS AS ROW START
valid to column (datetime2) with GENERATED ALWAYS AS ROW END
PERIOD FOR SYSTEM_TIME([VALIDFROMCOLUMN],[VALIDTOCOLUMN])

WITH (SYSTEM_VERSIONING = ON(HISTORY_TABLE=[HISTORYTABLE]));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you drop a Temporal Table?

A

ALTER TABLE [TABLENAME] SET (SYSTEM_VERSIONING=OFF)
GO

DROP TABLE [TABLENAME]
GO

DROP TABLE [TABLEHISTORYNAME]
GO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the query syntax for selecting data from a temporal table?

A
FOR SYSTEM TIME 
[AS OF ]
[FROM  TO ]
[BETWEEN  AND ]
[CONTAINED IN ( , )]
[ALL]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly