Presentation is loading. Please wait.

Presentation is loading. Please wait.

A time travel with temporal tables

Similar presentations


Presentation on theme: "A time travel with temporal tables"— Presentation transcript:

1 A time travel with temporal tables
Leonel Abreu – #516 | Bucharest 2016

2 Agenda What’s a Temporal Table? It’s useful for A Short “How to”
Advantages and how to use it It’s useful for Auditing efects Disaster Recovery Trending Analytics A Short “How to” Scenario and demo

3 What is a temporal table?
Also known as System Versioned Because keep changes Just two extra columns To define periods Finally a second table Which contains the history A system-versioned temporal table is a new type of user table in SQL Server 2016, designed to keep a full history of data changes and allow easy point in time analysis. This type of temporal table is referred to as a system-versioned temporal table because the period of validity for each row is managed by the system (i.e. database engine). Every temporal table has two explicitly defined columns, each with a datetime2 data type. These columns are referred to as period columns. These period columns are used exclusively by the system to record period of validity for each row whenever a row is modified. In addition to these period columns, a temporal table also contains a reference to another table with a mirrored schema. The system uses this table to automatically store the previous version of the row each time a row in the temporal table gets updated or deleted. This additional table is referred to as the history table, while the main table that stores current (actual) row versions is referred to as the current table or simply as the temporal table. During temporal table creation users can specify existing history table (must be schema compliant) or let system create default history table. Source:

4 How does it work? Source:

5 How does it work? Source:

6 Advantages Security Easy to maintain Can be used
Is not possible to modify the historical data Easy to maintain Additional coding to insert/update/delete data is not required Can be used For new tables For existing tables

7 Why temporal tables? Auditing Time Travel Recovering
All data changes and forensics if necessary Time Travel State of data as of any time in the past Recovering From accidental data changes, as undesired DELETE operations

8 Why temporal tables? Calculate Also BI Schema included
Trends over time Also BI Can be used to do SCD Schema included If the table structure is changed, it is also recorded

9 Why temporal tables? Real data sources are dynamic
6/26/2018 3:05 PM Why temporal tables? Real data sources are dynamic Historical data may be critical to business success Traditional databases fail to provide required insights Workarounds are… Complex, expensive, limited, inflexible, inefficient SQL Server 2016 makes life easy No change in programming model New Insights © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

10 Why temporal tables? Azure SQL Database Facts: Solution:
Microsoft Ignite 2015 6/26/2018 3:05 PM Why temporal tables? Facts: History is much bigger than actual data Retained between 3 and 10 years “Warm”: up to a few weeks/months “Cold”: rarely queried SELECT * FROM Department FOR SYSTEM_TIME AS OF ' ' Azure SQL Database Solution: history as a stretch table: PeriodEnd < “Now - 6 months” © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

11 How to implement it? Source:

12 How to implement it?

13 Query Clauses AS OF FROM TO SysStartTime SysStartTime <= date_time
SysEndTime > date_time FROM TO SysStartTime < end_date_time SysEndTime > start_date_time

14 Query Clauses BETWEEN AND CONTAINED IN ALL
SysStartTime <= end_date_time SysEndTime > start_date_time CONTAINED IN SysStartTime >= end_date_time SysEndTime <= start_date_time ALL Returns the union between the current and history table

15 Demo

16 Q & A

17 La revedere

18 Interesting resources
Getting Started with System-Versioned Tables Temporal Tables Changing the Schema of a System-Versioned Temporal Table Querying Data in a System-Versioned Temporal Table


Download ppt "A time travel with temporal tables"

Similar presentations


Ads by Google