Introduction to SQL 2016 Temporal Tables

Slides:



Advertisements
Similar presentations
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Advertisements

A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
CHAPTER 10 PHP MySQL Database
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration.
Scripting Just Enough SSIS to be Dangerous. 6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
Polybase and Time Travel (Temporal Tables) Stan Geiger #492 | Phoenix 2016.
3 A Guide to MySQL.
Getting started with Accurately Storing Data
With Temporal Tables and More
Fundamentals of DBMS Notes-1.
Trigger used in PosgreSQL
How to: SQL By: Sam Loch.
Web Systems & Technologies
Developing modern applications with Temporal Tables and JSON
Temporal Tables Sam Nasr, MCSA, MVP NIS Technologies July 22, 2017
Chapter 5 Introduction to SQL.
Katowice,
Temporal Databases Microsoft SQL Server 2016
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Insert, Update and the rest…
Temporal Databases Microsoft SQL Server 2016
Open Source Server Side Scripting Permissions & Users
Instructor: Jason Carter
A time travel with temporal tables
T-SQL: Simple Changes That Go a Long Way
Data Definition and Data Types
Example of a page header
The Ins and Outs of Partitioned Tables
Module 5: Implementing Data Integrity by Using Constraints
It’s About Time : Temporal Table Support in SQL Server 2016/2017
ISC440: Web Programming 2 Server-side Scripting PHP 3
SQL 101.
SQL Tutorial.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Traveling in time with SQL Server 2017
It’s About Time : Temporal Table Support in SQL Server 2016/2017
Insert, Update, Delete Manipulating Data.
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Introduction To Structured Query Language (SQL)
SQL DATA CONSTRAINTS.
Adding history to crud (Really) DINO ESPOSITO
Please support our sponsors
Introduction To Structured Query Language (SQL)
Structured Query Language
Data Time Travel with Temporal Tables
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
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.
XML? What’s this doing in my database? Adam Koehler
Data Time Travel with Temporal Tables
Presentation transcript:

Introduction to SQL 2016 Temporal Tables Vicky Harp

About Me Working with SQL Server since 2001 Working at Idera since 2004 Twitter: @vickyharp Email: vicky.harp@idera.com

Thank You Sponsors! Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration area to be entered in additional drawings. Want more free training? Check out the Houston Area SQL Server User Group which meets on the 2nd Tuesday of each month. Details at http://houston.sqlpass.org

Shopping Cart Contents Data Changes Over Time Postal Codes Physical Addresses Email Addresses Shopping Cart Contents

Data Changes For Different Reasons Customer Address Customer Moved Street Name Changed Typo When Entering Data Data Corruption

Temporal Databases Defined in SQL:2011 Specification Available from multiple RDBMS vendors SQL Server: System Versioned Temporal Tables

Types of Temporal Data Application Time / Real World Time Marie moved from Texas to California on November 15, 2015 System Time Marie’s address was changed from Texas to California on February 10, 2016

AdventureWorks Bike Shop October 2015 – Marie buys a bike in Texas November 2015 – Marie moves to California January 2016 – An invalid email promotion is sent out to people in Texas February 2016 – Marie buys a bike in California March 2016 – AdventureWorks sends a coupon to apologize for the invalid promotion in Texas

AdventureWorks Bike Shop Before Temporal Tables Date Activity Temporal Type System Data Reality October 2015 Marie buys a bike in Texas November 2015 Marie moves to California January 2016 Invalid email promotion to people in Texas February 2016 Marie buys a bike in California March 2016 Company wants to send a coupon to people in Texas

AdventureWorks Bike Shop Before Temporal Tables Date Activity Temporal Type System Data Reality October 2015 Marie buys a bike in Texas System November 2015 Marie moves to California Real World January 2016 Invalid email promotion to people in Texas February 2016 Marie buys a bike in California March 2016 Company wants to send a coupon to people in Texas

AdventureWorks Bike Shop Before Temporal Tables Date Activity Temporal Type System Data Reality October 2015 Marie buys a bike in Texas System Marie in Texas November 2015 Marie moves to California Real World January 2016 Invalid email promotion to people in Texas Marie in Texas Marie receives email February 2016 Marie buys a bike in California Marie in California March 2016 Company wants to send a coupon to people in Texas Marie does not receive coupon

AdventureWorks Bike Shop Before Temporal Tables Date Activity Temporal Type System Data Reality October 2015 Marie buys a bike in Texas System Marie in Texas November 2015 Marie moves to California Real World Marie in California January 2016 Invalid email promotion to people in Texas Marie in Texas Marie receives email Marie in California Marie receives email February 2016 Marie buys a bike in California March 2016 Company wants to send a coupon to people in Texas Marie does not receive coupon Marie is entitled to a coupon

System Versioned Temporal Tables Adds a history table to a user table Old rows are moved to history table as data changes History can be queried with new TSQL syntax Requires no changes to applications

System Versioned Temporal Tables User Table History Table Update Row Old Row select * from myTable select * from myTable for system_time as of ‘2016-01-01’

AdventureWorks Bike Shop With Temporal Tables Date Activity Temporal Type System Data Reality October 2015 Marie buys a bike in Texas System Marie in Texas November 2015 Marie moves to California Real World Marie in California January 2016 Invalid email promotion to people in Texas Marie in Texas Marie receives email Marie in California Marie receives email February 2016 Marie buys a bike in California March 2016 Company wants to send a coupon to people in Texas Marie receives a coupon Marie is entitled to a coupon

Use Cases Accessing history data Auditing data changes Repairing invalid data on a granular basis

Creating System Versioned Temporal Tables Create new table Add history to existing table Combine existing table and existing history table

Current and History Tables Must have the same columns May have different physical structure May be differently indexed May be partitioned, columnstore, and/or memory-optimized

Creating System Versioned Temporal Tables create table PersonTemporal ( BusinessEntityID int not null primary key clustered , FirstName dbo.Name not null , LastName dbo.Name not null , City nvarchar(30) , State dbo.Name , SystemStartTime datetime2 generated always as row start not null , SystemEndTime datetime2 generated always as row end not null , Period for System_Time (SystemStartTime,SystemEndTime) ) with (system_versioning = on (history_table = PersonTemporalHistory) );

Maintaining System Versioned Temporal Tables Cannot drop, truncate, or switch out partitions Cannot delete from history table System versioning columns can be hidden

DEMO

Querying System Versioned Temporal Tables FOR SYSTEM TIME clause AS OF FROM (start) to (end) BETWEEN (start) and (end) CONTAINED IN (start, end) ALL

Querying System Versioned Temporal Tables AS OF Value in table as of that date Did not need to be modified ON that date Example: Updated Marie’s record to California on February 5 As of January she’s in Texas As of March she is in California

For System Time Examples Jan 1 Jan 2 Jan 3 Jan 4 Jan 5 Jan 6

For System Time Examples Jan 1 Jan 2 Jan 3 Jan 4 Jan 5 Jan 6 AS OF Jan 3

Querying System Versioned Temporal Tables FROM (start) to (end) Value(s) in table from start date to end date EXCLUSIVE of end date Example: Updated Marie’s record to California on February 5 From January 10 to February 10 she’s in Texas and California From January 5 to February 5 she’s in Texas ONLY

For System Time Examples Jan 1 Jan 2 Jan 3 Jan 4 Jan 5 Jan 6 FROM Jan 2 TO Jan 4

Querying System Versioned Temporal Tables BETWEEN (start) and (end) Value(s) in table from start date to end date INCLUSIVE of end date Example: Updated Marie’s record to California on February 5 From January 10 to February 10 she’s in Texas and California From January 5 to February 5 she’s in Texas and California

For System Time Examples Jan 1 Jan 2 Jan 3 Jan 4 Jan 5 Jan 6 BETWEEN Jan 2 AND Jan 4

Querying System Versioned Temporal Tables CONTAINED IN (start, end) Value(s) in table from start date to end date Must both start and end in the timeframe Therefore all data will be from the history table Example: Inserted Marie’s Texas record November 10 Updated Marie’s record to California on February 5 Contained in (November 1, March 1) returns Marie’s Texas record Contained in (February 1, March 1) returns no data for Marie

For System Time Examples Jan 1 Jan 2 Jan 3 Jan 4 Jan 5 Jan 6 CONTAINED IN Jan 2, Jan 4

Querying System Versioned Temporal Tables ALL Returns all rows from current and history table Any restrictions come from WHERE clause Example: Inserted Marie’s Texas record November 10 Updated Marie’s record to California on February 5 Corrected typo on February 6 ALL returns Nov 10, Feb 5, and Feb 6

For System Time Examples Jan 1 Jan 2 Jan 3 Jan 4 Jan 5 Jan 6 ALL

DEMO

Review System versioned tables available in SQL 2016 Versioning may be turned on and off Current and history tables can be separately queried Use FOR SYSTEM TIME clause to automatically locate in the correct table

Thank You!