SlideShare a Scribd company logo
SQL Server 2016 –
Some New Features
@anniexu1990
Agenda
• IF EXISTS
• Text Split
• TemporalTables
• Column stored indexes
IF EXISTS
--in versions before 2016
IF OBJECT_ID('[dbo].[V_319AdHocObjects]') IS NOT NULL
BEGIN
DROPVIEW [dbo].[V_319AdHocObjects];
END;
GO
CREATEVIEW [dbo].[V_319AdHocObjects]
AS
SELECT name AS object_name,
SCHEMA_NAME(schema_id) AS schema_name,
x.type_desc
FROM sys.objects x
LEFT JOIN sys.dm_exec_procedure_statsAS d ON
OBJECT_NAME(d.object_id, d.database_id) = name
WHERE SCHEMA_NAME(schema_id) <> 'sys';
--in versions 2016
DROPVIEW IF EXISTS [dbo].[V_319AdHocObjects];
GO
CREATEVIEW [dbo].[V_319AdHocObjects]
AS
SELECT name AS object_name,
SCHEMA_NAME(schema_id) AS schema_name,
x.type_desc
FROM sys.objects x
LEFT JOIN sys.dm_exec_procedure_statsAS d ON
OBJECT_NAME(d.object_id, d.database_id) = name
WHERE SCHEMA_NAME(schema_id) <> 'sys';
TEXT Split
SELECT [ID],
[REPORTING_SEGMENT]
FROM [Ad_Hoc].[dbo].[Service_Requests];
-- use 2016 new scirpt string_split to get number of IDs per reporting_Setment
SELECT value AS reporting_seg,
COUNT([ID])AS countofrequests
FROM [Ad_Hoc].[dbo].[Service_Requests]
CROSS APPLY string_split([REPORTING_SEGMENT], ',')
GROUP BY value;
TemporalTables
USE [Ad_Hoc]
GO
CREATETABLE [dbo].[DataAccuracy_GPM_Temporal](
[ID] int Identity(1,1) Primary Key,
[DataType] [varchar](20) NULL,
[System Name] [varchar](20) NULL,
[Date] [date] NULL,
[Model Field] [nvarchar](255) NULL,
[SourceValue] [money] NULL,
[GPTValue] [money] NULL,
[ModelValue] [decimal](14, 2) NULL
,SysStartTime datetime2GENERATEDALWAYS AS ROW
START HIDDEN NOT NULL
,SysEndTime datetime2GENERATEDALWAYS AS ROW
END HIDDEN NOT NULL
,PERIOD FOR SYSTEM_TIME (SysStartTime,SysEndTime))
WITH (SYSTEM_VERSIONING = ON
(HISTORY_TABLE=dbo.DataAccuracy_GPM_History));
Select [ID]
,[DataType]
,[System Name]
,[Date]
,[Model Field]
,[SourceValue]
,[GPTValue]
,[ModelValue]
,[SysStartTime]
,[SysEndTime]
--ChangeTimezone
--,convert(smalldatetime,[SysStartTime]ATTIME ZONE
'UTC'ATTIME ZONE 'Eastern StandardTime') as
'SystemStartTimeEST'
--,Case when [SysEndTime] = '9999-12-31
23:59:59.9999999' then [SysEndTime]ATTIME ZONE 'UTC'
--ELSE convert(smalldatetime, [SysEndTime]ATTIME
ZONE 'UTC'ATTIME ZONE 'Eastern StandardTime') end as
'SystemEndTimeEST'
from [dbo].[DataAccuracy_GPM_Temporal]
-- For SYSTEM_TIME FROM '2017-06-05 19:12:45.8094962'
to '2017-06-05 19:18:45.8094962'
-- For SYSTEM_TIME CONTAINED IN ( '2017-06-05
19:12:45.8094962', '2017-06-05 19:18:45.8094962')
Columnstore Indexes
--create normal rowstore index
CREATECLUSTERED INDEX [ClusteredIndex-RequestID]ON
[dbo].[Service_Requests_NormalIndex];
GO
--result normal index remember to show plan
SET STATISTICSTIME ON
SELECT [REQ_TYPE]
,count([ID])
FROM [Ad_Hoc].[dbo].[Service_Requests_NormalIndex]
group by [REQ_TYPE];
SET STATISTICSTIME OFF
go
-- create columnstore index
CREATECLUSTERED COLUMNSTORE INDEX [SR_ColumnStoreIndex]
ON Service_Requests_ColumnStoreIndex;
GO
--result
SET STATISTICSTIME ON
SELECT [REQ_TYPE]
,count([ID])
FROM [Ad_Hoc].[dbo].[Service_Requests_ColumnStoreIndex]
group by [REQ_TYPE];
SET STATISTICSTIME OFF
go

More Related Content

Similar to Sql server 2016 – some new features

DNN Database Tips & Tricks
DNN Database Tips & TricksDNN Database Tips & Tricks
DNN Database Tips & Tricks
Will Strohl
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
Vidyasagar Mundroy
 
supporting t-sql scripts for Heap vs clustered table
supporting t-sql scripts for Heap vs clustered tablesupporting t-sql scripts for Heap vs clustered table
supporting t-sql scripts for Heap vs clustered table
Mahabubur Rahaman
 
171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx
sukrithlal008
 
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdfI am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
irshadkumar3
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworks
Bruno Rocha
 
Designer's Favorite New Features in SQLServer
Designer's Favorite New Features in SQLServerDesigner's Favorite New Features in SQLServer
Designer's Favorite New Features in SQLServer
Karen Lopez
 
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Julian Hyde
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
Norberto Leite
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)
MongoDB
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 
Neo4j: Import and Data Modelling
Neo4j: Import and Data ModellingNeo4j: Import and Data Modelling
Neo4j: Import and Data Modelling
Neo4j
 
When to NoSQL and when to know SQL
When to NoSQL and when to know SQLWhen to NoSQL and when to know SQL
When to NoSQL and when to know SQL
Simon Elliston Ball
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
Qureshi Tehmina
 
Nko workshop - node js & nosql
Nko workshop - node js & nosqlNko workshop - node js & nosql
Nko workshop - node js & nosqlSimon Su
 

Similar to Sql server 2016 – some new features (20)

DNN Database Tips & Tricks
DNN Database Tips & TricksDNN Database Tips & Tricks
DNN Database Tips & Tricks
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
supporting t-sql scripts for Heap vs clustered table
supporting t-sql scripts for Heap vs clustered tablesupporting t-sql scripts for Heap vs clustered table
supporting t-sql scripts for Heap vs clustered table
 
171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx
 
SAS Internal Training
SAS Internal TrainingSAS Internal Training
SAS Internal Training
 
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdfI am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworks
 
Mysql rab2-student
Mysql rab2-studentMysql rab2-student
Mysql rab2-student
 
Mysql rab2-student
Mysql rab2-studentMysql rab2-student
Mysql rab2-student
 
Designer's Favorite New Features in SQLServer
Designer's Favorite New Features in SQLServerDesigner's Favorite New Features in SQLServer
Designer's Favorite New Features in SQLServer
 
Msql
Msql Msql
Msql
 
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
 
Polyalgebra
PolyalgebraPolyalgebra
Polyalgebra
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
Neo4j: Import and Data Modelling
Neo4j: Import and Data ModellingNeo4j: Import and Data Modelling
Neo4j: Import and Data Modelling
 
When to NoSQL and when to know SQL
When to NoSQL and when to know SQLWhen to NoSQL and when to know SQL
When to NoSQL and when to know SQL
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
 
Nko workshop - node js & nosql
Nko workshop - node js & nosqlNko workshop - node js & nosql
Nko workshop - node js & nosql
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

Sql server 2016 – some new features

  • 1. SQL Server 2016 – Some New Features @anniexu1990
  • 2. Agenda • IF EXISTS • Text Split • TemporalTables • Column stored indexes
  • 3. IF EXISTS --in versions before 2016 IF OBJECT_ID('[dbo].[V_319AdHocObjects]') IS NOT NULL BEGIN DROPVIEW [dbo].[V_319AdHocObjects]; END; GO CREATEVIEW [dbo].[V_319AdHocObjects] AS SELECT name AS object_name, SCHEMA_NAME(schema_id) AS schema_name, x.type_desc FROM sys.objects x LEFT JOIN sys.dm_exec_procedure_statsAS d ON OBJECT_NAME(d.object_id, d.database_id) = name WHERE SCHEMA_NAME(schema_id) <> 'sys'; --in versions 2016 DROPVIEW IF EXISTS [dbo].[V_319AdHocObjects]; GO CREATEVIEW [dbo].[V_319AdHocObjects] AS SELECT name AS object_name, SCHEMA_NAME(schema_id) AS schema_name, x.type_desc FROM sys.objects x LEFT JOIN sys.dm_exec_procedure_statsAS d ON OBJECT_NAME(d.object_id, d.database_id) = name WHERE SCHEMA_NAME(schema_id) <> 'sys';
  • 4. TEXT Split SELECT [ID], [REPORTING_SEGMENT] FROM [Ad_Hoc].[dbo].[Service_Requests]; -- use 2016 new scirpt string_split to get number of IDs per reporting_Setment SELECT value AS reporting_seg, COUNT([ID])AS countofrequests FROM [Ad_Hoc].[dbo].[Service_Requests] CROSS APPLY string_split([REPORTING_SEGMENT], ',') GROUP BY value;
  • 5. TemporalTables USE [Ad_Hoc] GO CREATETABLE [dbo].[DataAccuracy_GPM_Temporal]( [ID] int Identity(1,1) Primary Key, [DataType] [varchar](20) NULL, [System Name] [varchar](20) NULL, [Date] [date] NULL, [Model Field] [nvarchar](255) NULL, [SourceValue] [money] NULL, [GPTValue] [money] NULL, [ModelValue] [decimal](14, 2) NULL ,SysStartTime datetime2GENERATEDALWAYS AS ROW START HIDDEN NOT NULL ,SysEndTime datetime2GENERATEDALWAYS AS ROW END HIDDEN NOT NULL ,PERIOD FOR SYSTEM_TIME (SysStartTime,SysEndTime)) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE=dbo.DataAccuracy_GPM_History)); Select [ID] ,[DataType] ,[System Name] ,[Date] ,[Model Field] ,[SourceValue] ,[GPTValue] ,[ModelValue] ,[SysStartTime] ,[SysEndTime] --ChangeTimezone --,convert(smalldatetime,[SysStartTime]ATTIME ZONE 'UTC'ATTIME ZONE 'Eastern StandardTime') as 'SystemStartTimeEST' --,Case when [SysEndTime] = '9999-12-31 23:59:59.9999999' then [SysEndTime]ATTIME ZONE 'UTC' --ELSE convert(smalldatetime, [SysEndTime]ATTIME ZONE 'UTC'ATTIME ZONE 'Eastern StandardTime') end as 'SystemEndTimeEST' from [dbo].[DataAccuracy_GPM_Temporal] -- For SYSTEM_TIME FROM '2017-06-05 19:12:45.8094962' to '2017-06-05 19:18:45.8094962' -- For SYSTEM_TIME CONTAINED IN ( '2017-06-05 19:12:45.8094962', '2017-06-05 19:18:45.8094962')
  • 6. Columnstore Indexes --create normal rowstore index CREATECLUSTERED INDEX [ClusteredIndex-RequestID]ON [dbo].[Service_Requests_NormalIndex]; GO --result normal index remember to show plan SET STATISTICSTIME ON SELECT [REQ_TYPE] ,count([ID]) FROM [Ad_Hoc].[dbo].[Service_Requests_NormalIndex] group by [REQ_TYPE]; SET STATISTICSTIME OFF go -- create columnstore index CREATECLUSTERED COLUMNSTORE INDEX [SR_ColumnStoreIndex] ON Service_Requests_ColumnStoreIndex; GO --result SET STATISTICSTIME ON SELECT [REQ_TYPE] ,count([ID]) FROM [Ad_Hoc].[dbo].[Service_Requests_ColumnStoreIndex] group by [REQ_TYPE]; SET STATISTICSTIME OFF go