@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Writing queries in SQL Server 2016
2017
Andrea Martorana Tusa
@bruco441
Widex A/S Danmark
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Many thanks to our sponsors & partners!
GOLD
SILVER
PARTNERS
PLATINUM
POWERED BY
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• First name: Andrea. Last name: Martorana Tusa.
• Italian, working by Widex a danish company which manufactures
hearing aids, as BI Specialist. Previously worked for 15 years as BI
developer in an italian bank. Focused on database development,
datawarehousing, cube development, reporting, data analysis, etc.
• Speaker at SQL Saturdays, and other community-driven events in
Europe, (MS Cloud Summit, SQL Konferenz, SQL Nexus, SQL Days,
Dataminds Connect ...). Speaker in webinars for PASS Italian VC, DW/BI
VC.
• Author for sqlservercentral.com, sqlshack.com, UGISS (User Group
Italiano SQL Server).
Speaker info
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• New statements and clause in SQL Server 2016-17
• Querying temporal tables
• JSON files
Agenda
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• No more select from system tables. Now Drop If Exists
(aka DIE) any object.
• Statement applies to following objects: AGGREGATE,
ASSEMBLY, VIEW, DATABASE, DEFAULT, FUNCTION,
INDEX, PROCEDURE, TABLE, ROLE, RULE, SCHEMA,
SECURITY POLICY, SEQUENCE, SYNONYM, TRIGGER,
TYPE, USER
DROP IF EXISTS
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• Combine CREATE and ALTER statements and create
object if it not exists or alter if it is already created.
• Statement applies to following objects: VIEWS,
STORED PROCEDURES, FUNCTIONS, TRIGGERS.
CREATE OR ALTER
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• Removes space character or other specified characters
from the start or the end of a string.
• To be used replacing RTRIM/LTRIM
• NB: TRIM is available only from SQL Server 2017.
TRIM
TRIM ([characters FROM] string)
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• Standard binary IIF function. Condition/condition
TRUE/condition FALSE.
• To be used for simple cases to replace CASE
WHEN statement.
• NB: IIF is available since SQL Server 2012.
IIF
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
String split solution is a common request in all forums and support sites. You can find
a bunch of documentation on-line.
Suppose you receive a string in this format:
STRING_SPLIT
Danmark København;Odense;Roskilde;Aaruhs
And want to translate the columns into rows with a function:
Danmark København
Danmark Odense
Danmark Roskilde
Danmark Aarhus
You can do it with a SQL user-defined function. And now in SQL Server 2016 there’s the
function STRING_SPLIT. You don’t need to built your own UDF anymore!
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• STRING_AGG is the opposite to STRING_SPLIT. The
function concatenates the values passed from a query
and places separator between them. The separator is
not added at the end of the string
• NB: STRING_AGG is available only from SQL Server
2017.
STRING_AGG
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• Concatenate With Separator; returns a string resulting
from the concatenation, of two or more string values.
It separates those concatenated string values with the
delimiter specified in the first function argument
• NB: CONCAT_WS is available only from SQL Server
2017.
CONCAT_WS
CONCAT_WS ( separator, argument1, argument1 [,
argumentN]… )
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• Escapes special characters in texts and returns
text with escaped characters. Used for example
to format JSON files.
STRING_ESCAPE
STRING_ESCAPE( text , type )
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• Performs a transformation over the input string,
replacing a set of characters with others passed as
argument.
• NB: TRANSLATE is available only from SQL Server 2017.
TRANSLATE
TRANSLATE (inputString, characters, translations)
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• New system stored procedure available from SQL Server 2016.
• Used to embed into SQL Server external programming
languages. First release in 2016 supported R, in 2017 support
includes Python, too.
sp_execute_external_script
sp_execute_external_script
@language = N'language',
@script = N'script'
[ , @input_data_1 = N'input_data_1' ]
[ , @input_data_1_name = N'input_data_1_name' ]
[ , @output_data_1_name = N'output_data_1_name' ]
[ , @parallel = 0 | 1 ]
[ , @params = N'@parameter_name data_type [ OUT | OUTPUT ] [ ,...n ]' ]
[ , @parameter1 = 'value1' [ OUT | OUTPUT ] [ ,...n ] ]
R/Python
Script written in the selected language
Input dataset
Output dataset
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• SQL Server 2016 introduced native support for JSON to
combine relational and NoSQL concepts. You can easily
transform relational to semi-structured data and vice-versa.
• JSON documents can be processed using standard T-SQL
features. You can therefore store them in tables, set
relationships between them, and query both scalar and JSON
values in one or more tables by using full Transact-SQL.
• As JSON is a text format, it is stored in varchar or nvarchar
columns and is indexed as plain text. There’s no JSON data
type, as in the case of XML.
JSON
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• Some functions are available to import, query,
process JSON files in SQL Server:
– ISJSON
– JSON_VALUE
– JSON_QUERY
– JSON_MODIFY
– OPENJSON
– FOR JSON
JSON
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
• Temporal tables, also called
system-versioned tables, allow
SQL Server to automatically
keep history of the data in the
table.
• Temporal tables keep the
history of the data, tracking all
changes with a start and end
date, to mark when the record
was active.
Temporal tables
The current table contains the value for each row
The history table contains each previous value
for each row, if any, and the start time and end
time for the period for which it was valid
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Temporal tables
CREATE TABLE Department
(
DeptID int NOT NULL PRIMARY KEY CLUSTERED
, DeptName varchar(50) NOT NULL
, ManagerID INT NULL
, ParentDeptID int NULL
, SysStartTime datetime2 GENERATED ALWAYS AS ROW START NOT NULL
, SysEndTime datetime2 GENERATED ALWAYS AS ROW END NOT NULL
, PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime)
)
WITH
(
SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.DepartmentHistory)
)
;
Start and end date always in the format datetime2
Temporal table
outlines
Primary key definition mandatory
Definition for destination table:
a) Hidden
b) Default
c) User-defined
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
How to query temporal tables
New clause FOR SYSTEM
TIME in the SELECT
statement, with five sub-
clauses to query data
across the current and
history tables.
SELECT * FROM Employee
FOR SYSTEM_TIME
BETWEEN '2014-01-01 00:00:00.0000000' AND '2015-01-01 00:00:00.0000000'
WHERE EmployeeID = 1000 ORDER BY ValidFrom;
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Q & A

More Related Content

ODP
Adapting Apache OpenOffice for adoption in Regione Emilia-Romagna
PPTX
From XML to MARC. RDF behind the scenes.
PDF
Yann Nicolas - Elag 2018 : From XML to MARC
PDF
Geospatial querying in Apache Marmotta - ApacheCon Big Data Europe 2015
PDF
LDQL: A Query Language for the Web of Linked Data
PDF
A Context-Based Semantics for SPARQL Property Paths over the Web
PDF
Grails And The Semantic Web
PDF
Linked Data, Ontologies and Inference
Adapting Apache OpenOffice for adoption in Regione Emilia-Romagna
From XML to MARC. RDF behind the scenes.
Yann Nicolas - Elag 2018 : From XML to MARC
Geospatial querying in Apache Marmotta - ApacheCon Big Data Europe 2015
LDQL: A Query Language for the Web of Linked Data
A Context-Based Semantics for SPARQL Property Paths over the Web
Grails And The Semantic Web
Linked Data, Ontologies and Inference

What's hot (11)

PDF
8th TUC Meeting -
PDF
Harnessing The Semantic Web
PDF
Eclipse RDF4J - Working with RDF in Java
PDF
Overview of the SPARQL-Generate language and latest developments
PPTX
Semantic Variation Graphs the case for RDF & SPARQL
PDF
Explicit Semantics in Graph DBs Driving Digital Transformation With Neo4j
PDF
Towards a Commons RDF Library - ApacheCon Europe 2014
PDF
Intro to R statistic programming
PPTX
R training at Aimia
PPT
Intro to XML in libraries
PDF
Jesús Barrasa
8th TUC Meeting -
Harnessing The Semantic Web
Eclipse RDF4J - Working with RDF in Java
Overview of the SPARQL-Generate language and latest developments
Semantic Variation Graphs the case for RDF & SPARQL
Explicit Semantics in Graph DBs Driving Digital Transformation With Neo4j
Towards a Commons RDF Library - ApacheCon Europe 2014
Intro to R statistic programming
R training at Aimia
Intro to XML in libraries
Jesús Barrasa
Ad

Similar to ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017 (20)

PDF
Sql server 2016: System Databases, data types, DML, json, and built-in functions
PPTX
SQL Server 2016 JSON
PDF
FREE Sql Server syllabus
PDF
Sql server common interview questions and answers page 4
PPTX
What's new in DB2 for i - IBM i 7.3 TR1 and IBM i 7.2 TR5 - final.pptx
PPTX
Compare SQL changes|SQL Database Modeler
PPTX
Azure SQL & SQL Server 2016 JSON
PPTX
New Features of SQL Server 2016
PPTX
Sql Server 2016 and JSON
PPT
MS SQL Server.ppt
PPT
Sql server introduction to sql server
DOCX
Sql server 2008 r2 programmability datasheet
PDF
Sql overview-1232931296681161-1
PPTX
Sql server
PPT
New features of sql server 2005
PDF
Native JSON Support in SQL2016
PPTX
What's new in SQL Server Integration Services 2012?
PDF
Tech Jam 01 - Database Querying
PPT
MS SQL Server.ppt sql
Sql server 2016: System Databases, data types, DML, json, and built-in functions
SQL Server 2016 JSON
FREE Sql Server syllabus
Sql server common interview questions and answers page 4
What's new in DB2 for i - IBM i 7.3 TR1 and IBM i 7.2 TR5 - final.pptx
Compare SQL changes|SQL Database Modeler
Azure SQL & SQL Server 2016 JSON
New Features of SQL Server 2016
Sql Server 2016 and JSON
MS SQL Server.ppt
Sql server introduction to sql server
Sql server 2008 r2 programmability datasheet
Sql overview-1232931296681161-1
Sql server
New features of sql server 2005
Native JSON Support in SQL2016
What's new in SQL Server Integration Services 2012?
Tech Jam 01 - Database Querying
MS SQL Server.ppt sql
Ad

More from ITCamp (20)

PDF
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
PDF
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
PDF
ITCamp 2019 - Peter Leeson - Managing Skills
PPTX
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
PDF
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
PDF
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
PPTX
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
PPTX
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
PPTX
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
PPTX
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
PPTX
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
PPTX
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
PPTX
ITCamp 2019 - Andy Cross - Business Outcomes from AI
PDF
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
PDF
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
PPTX
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
PPTX
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
PDF
ITCamp 2019 - Peter Leeson - Vitruvian Quality
PDF
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
PDF
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...

Recently uploaded (20)

PDF
SaaS reusability assessment using machine learning techniques
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PPTX
agenticai-neweraofintelligence-250529192801-1b5e6870.pptx
PDF
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
PPTX
SGT Report The Beast Plan and Cyberphysical Systems of Control
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
Connector Corner: Transform Unstructured Documents with Agentic Automation
PDF
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
PDF
Auditboard EB SOX Playbook 2023 edition.
PPTX
MuleSoft-Compete-Deck for midddleware integrations
PDF
Lung cancer patients survival prediction using outlier detection and optimize...
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PPTX
Microsoft User Copilot Training Slide Deck
PDF
4 layer Arch & Reference Arch of IoT.pdf
SaaS reusability assessment using machine learning techniques
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
agenticai-neweraofintelligence-250529192801-1b5e6870.pptx
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
SGT Report The Beast Plan and Cyberphysical Systems of Control
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
Enhancing plagiarism detection using data pre-processing and machine learning...
Early detection and classification of bone marrow changes in lumbar vertebrae...
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Connector Corner: Transform Unstructured Documents with Agentic Automation
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
Auditboard EB SOX Playbook 2023 edition.
MuleSoft-Compete-Deck for midddleware integrations
Lung cancer patients survival prediction using outlier detection and optimize...
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
Co-training pseudo-labeling for text classification with support vector machi...
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
Microsoft User Copilot Training Slide Deck
4 layer Arch & Reference Arch of IoT.pdf

ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017

  • 1. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Writing queries in SQL Server 2016 2017 Andrea Martorana Tusa @bruco441 Widex A/S Danmark
  • 2. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Many thanks to our sponsors & partners! GOLD SILVER PARTNERS PLATINUM POWERED BY
  • 3. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • First name: Andrea. Last name: Martorana Tusa. • Italian, working by Widex a danish company which manufactures hearing aids, as BI Specialist. Previously worked for 15 years as BI developer in an italian bank. Focused on database development, datawarehousing, cube development, reporting, data analysis, etc. • Speaker at SQL Saturdays, and other community-driven events in Europe, (MS Cloud Summit, SQL Konferenz, SQL Nexus, SQL Days, Dataminds Connect ...). Speaker in webinars for PASS Italian VC, DW/BI VC. • Author for sqlservercentral.com, sqlshack.com, UGISS (User Group Italiano SQL Server). Speaker info
  • 4. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • New statements and clause in SQL Server 2016-17 • Querying temporal tables • JSON files Agenda
  • 5. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • No more select from system tables. Now Drop If Exists (aka DIE) any object. • Statement applies to following objects: AGGREGATE, ASSEMBLY, VIEW, DATABASE, DEFAULT, FUNCTION, INDEX, PROCEDURE, TABLE, ROLE, RULE, SCHEMA, SECURITY POLICY, SEQUENCE, SYNONYM, TRIGGER, TYPE, USER DROP IF EXISTS
  • 6. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • Combine CREATE and ALTER statements and create object if it not exists or alter if it is already created. • Statement applies to following objects: VIEWS, STORED PROCEDURES, FUNCTIONS, TRIGGERS. CREATE OR ALTER
  • 7. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • Removes space character or other specified characters from the start or the end of a string. • To be used replacing RTRIM/LTRIM • NB: TRIM is available only from SQL Server 2017. TRIM TRIM ([characters FROM] string)
  • 8. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • Standard binary IIF function. Condition/condition TRUE/condition FALSE. • To be used for simple cases to replace CASE WHEN statement. • NB: IIF is available since SQL Server 2012. IIF
  • 9. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals String split solution is a common request in all forums and support sites. You can find a bunch of documentation on-line. Suppose you receive a string in this format: STRING_SPLIT Danmark København;Odense;Roskilde;Aaruhs And want to translate the columns into rows with a function: Danmark København Danmark Odense Danmark Roskilde Danmark Aarhus You can do it with a SQL user-defined function. And now in SQL Server 2016 there’s the function STRING_SPLIT. You don’t need to built your own UDF anymore!
  • 10. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • STRING_AGG is the opposite to STRING_SPLIT. The function concatenates the values passed from a query and places separator between them. The separator is not added at the end of the string • NB: STRING_AGG is available only from SQL Server 2017. STRING_AGG
  • 11. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • Concatenate With Separator; returns a string resulting from the concatenation, of two or more string values. It separates those concatenated string values with the delimiter specified in the first function argument • NB: CONCAT_WS is available only from SQL Server 2017. CONCAT_WS CONCAT_WS ( separator, argument1, argument1 [, argumentN]… )
  • 12. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • Escapes special characters in texts and returns text with escaped characters. Used for example to format JSON files. STRING_ESCAPE STRING_ESCAPE( text , type )
  • 13. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • Performs a transformation over the input string, replacing a set of characters with others passed as argument. • NB: TRANSLATE is available only from SQL Server 2017. TRANSLATE TRANSLATE (inputString, characters, translations)
  • 14. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • New system stored procedure available from SQL Server 2016. • Used to embed into SQL Server external programming languages. First release in 2016 supported R, in 2017 support includes Python, too. sp_execute_external_script sp_execute_external_script @language = N'language', @script = N'script' [ , @input_data_1 = N'input_data_1' ] [ , @input_data_1_name = N'input_data_1_name' ] [ , @output_data_1_name = N'output_data_1_name' ] [ , @parallel = 0 | 1 ] [ , @params = N'@parameter_name data_type [ OUT | OUTPUT ] [ ,...n ]' ] [ , @parameter1 = 'value1' [ OUT | OUTPUT ] [ ,...n ] ] R/Python Script written in the selected language Input dataset Output dataset
  • 15. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • SQL Server 2016 introduced native support for JSON to combine relational and NoSQL concepts. You can easily transform relational to semi-structured data and vice-versa. • JSON documents can be processed using standard T-SQL features. You can therefore store them in tables, set relationships between them, and query both scalar and JSON values in one or more tables by using full Transact-SQL. • As JSON is a text format, it is stored in varchar or nvarchar columns and is indexed as plain text. There’s no JSON data type, as in the case of XML. JSON
  • 16. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • Some functions are available to import, query, process JSON files in SQL Server: – ISJSON – JSON_VALUE – JSON_QUERY – JSON_MODIFY – OPENJSON – FOR JSON JSON
  • 17. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals • Temporal tables, also called system-versioned tables, allow SQL Server to automatically keep history of the data in the table. • Temporal tables keep the history of the data, tracking all changes with a start and end date, to mark when the record was active. Temporal tables The current table contains the value for each row The history table contains each previous value for each row, if any, and the start time and end time for the period for which it was valid
  • 18. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Temporal tables CREATE TABLE Department ( DeptID int NOT NULL PRIMARY KEY CLUSTERED , DeptName varchar(50) NOT NULL , ManagerID INT NULL , ParentDeptID int NULL , SysStartTime datetime2 GENERATED ALWAYS AS ROW START NOT NULL , SysEndTime datetime2 GENERATED ALWAYS AS ROW END NOT NULL , PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime) ) WITH ( SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.DepartmentHistory) ) ; Start and end date always in the format datetime2 Temporal table outlines Primary key definition mandatory Definition for destination table: a) Hidden b) Default c) User-defined
  • 19. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals How to query temporal tables New clause FOR SYSTEM TIME in the SELECT statement, with five sub- clauses to query data across the current and history tables. SELECT * FROM Employee FOR SYSTEM_TIME BETWEEN '2014-01-01 00:00:00.0000000' AND '2015-01-01 00:00:00.0000000' WHERE EmployeeID = 1000 ORDER BY ValidFrom;
  • 20. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Q & A