Temporal Tables Flashcards

1
Q

What elements are required in the table definition for a table to be capable of being a temporal table?

A

When you create a system-versioned temporal table, you need to make sure the table definition has all the following elements:

Image A primary key

Image Two columns defined as DATETIME2 with any precision, which are non-nullable and represent the start and end of the row’s validity period in the UTC time zone

Image A start column that should be marked with the option GENERATED ALWAYS AS ROW START

Image An end column that should be marked with the option GENERATED ALWAYS AS ROW END

Image A designation of the period columns with the option PERIOD FOR SYSTEM_TIME (, )

Image The table option SYSTEM_VERSIONING, which should be set to ON

Image A linked history table (which SQL Server can create for you) to hold the past states of modified rows

Optionally, you can mark the period columns as hidden so that when you’re querying the table with SELECT * they won’t be returned and when you’re inserting data they’ll be ignored.

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

Describe how the differences between the temporal table and its associated history table.

A

The history table is created with a mirrored schema, but has the following differences:

No primary key

a clustered index on (, ), with page compression if possible

Period columns that are not marked with any special options, like GENEREATED ALWAYS AS ROW START/END or HIDDEN

The history table is not marked with the option SYSTEM_VERSIONING

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

Describe the statement to enable versioning on a table.

A

SET (SYSTEM_VERSIONING = ON ( HISTORY_TABLE = ) );

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

Why is this statement necessary ALTER TABLE dbo.Employees ADD PERIOD FOR SYSTEM_TIME (sysstart, sysend);

A

This statement designates the columns in (, ) as period columns, which are a requirement for a table to be able to SYSTEM_VERSIONING to ON.

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

IF you want to see a past state of the data, correct to a certain point or period of time, you will query the current table followed by what statement?

A

SELECT … FROM FOR SYSTEM_TIME AS ;

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

List the sub-clauses which are used in the FOR SYSTEM_TIME clause

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