Final Study Topics Flashcards
What are the 4 types of table expressions?
Derived Tables
CTE
View
Inline Table-Valued Functions
What are the 3 millisecond values that datetime can have without rounding?
0, 3, 7
What is the only type of function that can be used and still be a SARG?
CAST(@DateVar as Date)
What datatypes can JSON elements contain?
String Number Boolean object array null
Where does WITH CHECK OPTION go within a View Creation Statement?
At the end of the statement:
Create view ViewName
as
Select * from table
with check option;
Which function statement is more efficient?
Inline Table Value Function (MultiStatement Table Value Function is slower)
What are the steps needed to insert into an identity field on a table?
SET IDENTITY_INSERT ON;
INSERT INTO TABLE (IDENTITY) VALUES (VALUE)
SET IDENTITY_INSERT OFF;
How can you get a the time in a different timezone when you have a datetime?
SWITCHOFFSET(DateTime AT TIME ZONE TimeZone, 0)
Examples of TimeZone are: ‘Pacific Standard Time’, ‘Eastern Standard Time’
What is the syntax for datefromparts?
DATEFROMPARTS(YEAR, MONTH, DAY, HOUR, MINUTES, SECONDS)
What does the EOMONTH function do? What is the syntax?
It gives the last day of the month passed to it:
EOMONTH(DateVar, MonthOffset)
IE: dateadd(day, 1, EOMONTH(sysdatetime(), -1)) gets the first day of the month
What is the syntax for creating a temporal table?
CREATE TABLE dbo.TableName
(
[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 do you query data from a temporal table?
SELECT * FROM dbo.TemporalTable
FOR SYSTEM_TIME
BETWEEN ‘2019-01-01 00:00:00.0000000’ AND ‘2020-01-01 00:00:00.0000000’
ORDER BY ValidFrom;