SKILL 2.4. Query Temporal data and non-relational data Flashcards

1
Q

Temporal Tables - Requirements

A

A primary key constraint

Two DATETIME2 columns with chosen precision to store the start and the end of the validity period of the row

The start column needs to be marked with the clause GENERATED ALWAYS AS ROW START

The end column needs to be marked with GENERATED ALWAYS AS ROW END

The table option SYSTEM_VERSIONING needs to be set to ON

A linked history table which SQL server creates for you

PERIOD FOR SYSTEM_TIME(“startcolumn”,”endcolumn”)

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

Temporal Tables - format

A

CREATE TABLE dbo.Products

(

productid INT NOT NULL

CONSTRAINT PK_dboProducts PRIMARY KEY(productid),

productname NVARCHAR(40) NOT NULL,

supplierid INT NOT NULL,

categoryid INT NOT NULL,

unitprice MONEY NOT NULL,

– below are additions related to temporal table

validfrom DATETIME2(3)

GENERATED ALWAYS AS ROW START HIDDEN NOT NULL,

validto DATETIME2(3)

GENERATED ALWAYS AS ROW END   HIDDEN NOT NULL,

PERIOD FOR SYSTEM_TIME (validfrom, validto)

)

WITH ( SYSTEM_VERSIONING = ON ( HISTORY_TABLE = dbo.ProductsHistory ) );

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

What does HIDDEN property do in a Temporal table

A

When using SELECT * it does not return that property

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

FOR SYSTEM_TIME AS OF

A

returns a table with rows which are between SysStartTime and SystemEndTime

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

FOR SYSTEM_TIME FROM datetime TO datetime

A

Returns table with values for all row versions that were active any time during the time specified, excluding the upper boundary

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

FOR SYSTEM_TIME BETWEEN datetime AND datetime

A

Returns table with values for all row versions that were active any time during the time specified, including the upper boundary

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

FOR SYSTEM_TIME CONTAINED IN(datetime,datetime)

A

Returns a table with the values for all row versions that were opened and closed within the specified range

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

FOR SYSTEM_TIME ALL

A

returns the union of rows that belong to the current history table

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

AT TIMEZONE

A

Period coulumns store time in the UTC time zone

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

XML document - characteristics

A

It is “well-formed”
XML documents are ordered - means not ordered by a criteria but the position of the elements matter
Case-Sensitive Unicode text

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

Difference between a Document and a Fragment

XML

A

The document has a single root node. If you delete that element you get a XML fragment

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

Most used metadata description of XML documents

A

XML Schema Description (XSD)

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

FOR XML RAW - output

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

FOR XML RAW - charcteristics

A

Its not a XML document because the root node is missing.
In RAW mode every row from the returned result set converts to a single element named row, and columns translate t attributes of this element

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

FOR XML AUTO

A

easy to use and returns query results as nested XML elements

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

What is important in a XML statement

A

Use ORDER BY statement because without the ORDER BY statement the order of the elements is unpredictable

Order of the SELECT statement defines the returned XML

17
Q

XQuery

A

is a standard language for browsing XML

Case sensitive

18
Q

FOR JSON AUTO

A

formats the JSON automatically.

You do not have much influence on the format of JSON

19
Q

FOR JSON PATH

A

You have much more influence than in JSON AUTO
You can nest elements with a “dot”

SELECT contactname AS [Contact.Name]
FROM Sales.Customers
FOR JSON PATH;

Result:
[

{

  "CustomerId":1, 

  "Company":"Customer NRZBB",

  "Contact":{ 

     "Name":"Allen, Michael"

  }

}

]

20
Q

FOR JSON - additional clauses

A

ROOT - adds single, top level member
INCLUDE_NULL_VALUES - includes nulls in the output - they are excluded by default
WITHOUT_ARRAY_WRAPPER - removes square brackets

21
Q

SWITCHOFFSET

A

SWITCHOFFSET function takes 2 arguments, the data type to be returned and the timezone required