It’s About Time : Temporal Table Support in SQL Server 2016/2017

Slides:



Advertisements
Similar presentations
By: Jose Chinchilla July 31, Jose Chinchilla MCITP: SQL Server 2008, Database Administrator MCTS: SQL Server 2005/2008, Business Intelligence DBA.
Advertisements

Auditing Database DDL Changes with SQLVer. About PASS The PASS community encompasses everyone who uses the Microsoft SQL Server or Business Intelligence.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
1 Copyright © 2004, Oracle. All rights reserved. Introduction.
Understanding SQL Server 2008 Change Data Capture Bret Stateham Training Manager Vortex Learning Solutions blogs.netconnex.com.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Chapter 7 SQL: Data Definition Pearson Education © 2009.
CPT-S Advanced Databases 11 Yinghui Wu EME 49.
1 Agenda TMA02 M876 Block 4. 2 Model of database development data requirements conceptual data model logical schema schema and database establishing requirements.
In this session, you will learn to: Manage databases Manage tables Objectives.
SQL Server DML Change Capture An overview of several useful SQL Server data change capture technologies Matt Smith Software Architect, Enterprise Data.
Carlos Bossy Quanta Intelligence SQL Server MCTS, MCITP BI CBIP, Data Mining Real-time Data Warehouse and Reporting Solutions.
Database Design: Solving Problems Before they Start! Ed Pollack Database Administrator CommerceHub.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
With Temporal Tables and More
Let’s Get Started! Steve Rezhener SQL Malibu and SQL Saturday in LA
SQL Server Statistics and its relationship with Query Optimizer
Temporal Tables Sam Nasr, MCSA, MVP NIS Technologies July 22, 2017
Katowice,
Temporal Databases Microsoft SQL Server 2016
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Temporal Databases Microsoft SQL Server 2016
Introduction to SQL 2016 Temporal Tables
A time travel with temporal tables
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
SSIS Project Deployment: The T-SQL Way
A time travel With temporal tables Leonel Abreu
Example of a page header
Ouch! Our Data Type Choices Did THAT?
Where I am at: Swagatika Sarangi MDM Lead PASS Summit SQL Saturdays
Database Code Management with VS 2017 and RedGate
It’s About Time : Temporal Table Support in SQL Server 2016/2017
Proper DataType Usage = Guaranteed Better Performance and Accuracy
Please support our sponsors
Traveling in time with SQL Server 2017
Save Time & Resources: Job Performance Tuning Strategies
Query Optimization Statistics: The Driving Force Behind Good Performance G. Vern Rabe -
Transforming Your Brain with SQL 2017 on Linux
SQL Azure Database – No CDC, No Problem!
Stop Wasting Time & Resources: Performance Tune Your Jobs
SSIS Project Deployment: The T-SQL Way
The Mac DBA, using Docker and SQL Operations Studio
Let’s Get Started! Rick Lowe
Introduction to Object-Relational Mapping for DBAs
Microsoft Azure for SQL Server Professionals
Data Model.
Save Time & Resources: Job Performance Tuning Strategies
Designing SSIS Packages for Performance
Unit I-2.
Adding history to crud (Really) DINO ESPOSITO
Please support our sponsors
Unleashing Stretched Databases
Contents Preface I Introduction Lesson Objectives I-2
Query Tuning Fundamentals
Triggers.
Data Time Travel with Temporal Tables
The Fast and Easy Methods to Automate your SQL Server builds
Patrick Partin What just happened?
SSRS – Thinking Outside the Report
Brodie Brickey SSIS Basics.
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
Do-It-Yourself Performance Monitoring
Simplify your daily tasks with DBATools!
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
Data Time Travel with Temporal Tables
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
T-SQL Tools: Simplicity for Synchronizing Changes Martin Perez.
Data Time Travel with Temporal Tables
Presentation transcript:

It’s About Time : Temporal Table Support in SQL Server 2016/2017 Vern Rabe RabeData, LLC It’s About Time : Temporal Table Support in SQL Server 2016/2017

Please Support Our Sponsors

Orange County User Group Local User Groups Orange County User Group 2rd Thursday of each month bigpass.pass.org Los Angeles User Group San Diego User Group 3rd Thursday of each odd month 1st & 3rd Thursday of each month meetup.com/sdsqlug sqlla.pass.org meetup.com/sdsqlbig Malibu User Group Los Angeles - Korean 3rd Wednesday of each month Every Other Tuesday sqlmalibu.pass.org sqlangeles.pass.org SQLSaturday Los Angeles June 9th SQLSaturday San Diego September 15th

Discount Code: SSDISODNS SQL Summit Annual International Conference November 6 -9 | Seattle, WA 2 Days of Pre-Cons 200+ sessions over 3 days Over 5,000 SQL Professionals Evening Networking Activities Discount Code: SSDISODNS

Vern Rabe Portland, OR independent consultant, trainer MCTA, MCDBA, MCSE, MCITP Co-VP Oregon PASS chapter Working with/focusing on SQL Server since 1993, starting with SQL Server 4.21a My first PC had a 10MB hard drive

Vern Rabe

What We’ll Cover What are we trying to solve What is a temporal table Creating and altering SELECT enhancements SQL Server 2016 temporal table limitations What’s new in SQL Server 2017

Use Cases Repeatable reports Changing validity periods Who made that change? (auditing) Monitoring business trends Repairing row-level corruption(not a replacement to BACKUP/RESTORE) Slowly Changing Dimension?

Definitions Temporal tables hold current and past versions of data Defined in ISO SQL:2011 What’s a timestamp? Instant, Interval (duration), Period (anchored duration) System Period Application Period Bi-Temporal Closed vs. Open ended Periods

Temporal Tables vs. CDC (Change Data Capture) CDC can be at column level CDC has less of a performance hit (Tlog) CDC is eventually current CDC relies on Agent Reliability CDC designed for short term use, e.g., for ETL incremental loads Temporal Tables designed to be long term, for complete row history Temporal Tables easy to query

SQL Server Temporal Table Base (current) table with attached history table Two datetime2 columns define System Period UTC based US – “CUT” (Coordinated Universal Time) French – “TUC” (Temps Universel Coordonné) System maintained INSERTs – Base table gets System Period columns set to “Now” and 9999-12-31. No History table activity UPDATEs – Base table row is copied to History table, terminated to “Now”. Base table row set to start “Now” DELETEs –Base table row is moved to History, terminated to “Now” Querying additions to T-SQL

Implementing in SQL Server CREATE/ALTER TABLE Two NOT NULL datetime2 columns to define period (any precision) GENERATED ALWAYS AS ROW START GENERATED ALWAYS AS ROW END Optional HIDDEN PERIOD FOR SYSTEM_TIME for these two columns (closed-open) Table option SYSTEM_VERSIONING ON Optionally specify history table name – schemas must match exactly ALTER can apply to existing non-temporal table (migrating history)

Syntax Basic CREATE • Specifying history table name • Specifying history table name for existing table – consistency check • ALTER existing base and history table •

Time Traveling Using T-SQL FOR SYSTEM_TIME AS OF <timestamp> • FROM <start_ timestamp> TO <end_ timestamp> • Closed-open BETWEEN <start_ timestamp> AND <end_timestamp> Closed-closed CONTAINED IN (<start_ timestamp>, <end_ timestamp>) Fully contained, closed-closed Not ISO ALL • Recovering from accidental DELETE/UPDATE •

Metadata sys.tables sys.columns sys.periods • temporal_type: 1=history, 2=current temporal_type_desc: HISTORY_TABLE (1) SYSTEM_VERSIONED_TEMPORAL_TABLE (2) history_table_id sys.columns generated_always_type: 1=start, 2=end generated_always_desc: AS_ROW_START AS_ROW_END NOT_APPLICABLE sys.periods • OBJECTPROPERTY & OBJECTPROPERTYEX TableTemporalType: 1=history, 2=current COLUMNPROPERTY GeneratedAlwaysType IsHidden

SQL Server 2016 Limitations Base table must have PK History table cannot have PK History table must be in same database as current table Querying temporal tables over Linked Server not allowed No data modification directly on History tables No INSERT/UPDATE directly on SYSTEM_TIME columns

SQL Server 2016 Limitations (cont.) Cannot be FILETABLE, cannot have FILESTREAM No constraints on history table (except DEFAULT, which is ineffective) In-Memory OLTP “mostly” implemented Truncate table not allowed No INSTEAD OF triggers No triggers on history table No history table chaining Manual changes to system clock can cause failures

New Features in SQL Server 2017 Limit life of history table contents System-versioned temporal tables now support CASCADE DELETE and CASCADE UPDATE

Summary Several uses Repeatable reports Trend analysis Data audit Repair row-level data corruption Base + History Table System Period (not Application Period) Fully system maintained Easy to create, easy to query

Resources SQL:2011 temporal summary http://www.sigmod.org/publications/sigmod-record/1209/pdfs/07.industry.kulkarni.pdf Temporal Data and the Relational Model C.J.Date Hugh Darwen Nikos A. Lorentzos Developing Time-Oriented Database Applications in SQL Richard T. Snodgrass

Thanks. Questions? Vern Rabe vern@rabedata.com @VernRabe