SQL SERVER & SQL AZURE
TEMPORAL TABLES
Davide Mauri
www.davidemauri.it | info@davidemauri.it
@mauridb
DAVIDE MAURI
 Microsoft Data Platform MVP since 2006
 Works with SQL Server from 6.5, on BI from 2003
 Specialized in Data SolutionArchitecture, Database Design, PerformanceTuning, High-
Performance DataWarehousing, BI, Big Data
 Very strong developer background
 Loves community!
 President of UGISS (Italian SQL Server UG) for 11Years, AppDevVG Leader since 2017
 Regular Speaker @ SQL Server events
 Director SW & Cloud @ Sensoria: http://www.sensoriafitness.com/
 E-mail: info@davidemauri.it -Twitter: @mauridb
 Blog: http://sqlblog.com/blogs/davide_mauri/default.aspx
LOVE AT FIRST SIGHT!
 TemporalTables
THINGSTO KEEP IN MIND
 Stored interval is half-open: [valid_from, valid_to)
 >= valid_fromAND < valid_to
 Stored interval is in UTC
TEMPORALTABLES
 Automatically keeps track of changed data (versioning)
 Along with period of validity
 Available in all editions of SQL Server (from the Express!)
 Available in SQL Azure
 ANSI 2011 compliant
 Provide native support for temporal queries
 Transparent to existing applications (if needed)
 Integrated with existing features (eg: Partitioning, Hekaton, ColumnStore)
 Integrated with new features (eg: Stretch Database)
TEMPORAL QUERIES
 SQL Server 2016 supports
 AS OF <date_time>
 FROM <start_date_time>TO <end_date_time>
 BETWEEN <start_date_time> AND <end_date_time>
 CONTAINED IN (<start_date_time> , <end_date_time>)
 ALL
 https://docs.microsoft.com/en-us/sql/relational-databases/tables/temporal-tables
http://www.ics.uci.edu/~alspaugh/cls/shr/allen.html
TEMPORALTABLES
 Some limitations compared to “classic” tables
 NoTRUNCATETABLE support
 INSTEADOF triggers not supported
 Temporal tables *can* be ALTERed
 A few limitations:
 Cannot add a computed columns
 Cannot add an Identity column
 Versioning can be turned on/off as we wish
TEMPORALTABLES
 SQL 2016:There is *no* automatic cleanup of versioning
 Stretch Database offer “a sort of” automatic archival (but still no cleaning!)
 Tips: https://msdn.microsoft.com/library/mt637341.aspx
 SQL vNext – Azure SQL:There *is* an automatic cleanup process of versioning
 https://docs.microsoft.com/en-us/azure/sql-database/sql-database-temporal-tables-
retention-policy
DEMO!
Let’s see some live action!
TEMPORALTABLES
 Temporal queries with other operators than “AS OF” can be tricky
 Especially if you’re joining temporal tables
 Rows are not unpacked and then packed back!
 Hugh Darwen http://www.dcs.warwick.ac.uk/~hugh/
DEMO!
Tricky stuff….
ADDITIONAL READS
 First Look at System-VersionedTemporalTables
 http://sqlmag.com/sql-server/first-look-system-versioned-temporal-tables-part-1-creating-
tables-and-modifying-data
 http://sqlmag.com/sql-server/first-look-system-versioned-temporal-tables-part-2-querying-
data-and-optimization-conside
 Usage Scenarios
 https://docs.microsoft.com/en-us/sql/relational-databases/tables/temporal-table-usage-
scenarios
 Temporal data (as a general topic)
 https://www.amazon.com/Time-Relational-Theory-Second-Management/dp/0128006315
 https://www.pluralsight.com/courses/working-with-temporal-data-sql-server
VOTE ON CONNECT
 Temporal support is good but can be improved! Help telling Microsoft you what
more:
 Add SQL Server Engine Support for Interval Queries (Intersection/Overlap and other
Allen’s interval algebra relations)
 https://connect.microsoft.com/SQLServer/Feedback/Details/780746
 TemporalTables: Connect Item Round Up
 http://sqlblog.com/blogs/adam_machanic/archive/2016/10/04/temporal-tables-connect-item-
round-up.aspx
THANKS!

SQL Server & SQL Azure Temporal Tables - V2

  • 1.
    SQL SERVER &SQL AZURE TEMPORAL TABLES Davide Mauri www.davidemauri.it | info@davidemauri.it @mauridb
  • 2.
    DAVIDE MAURI  MicrosoftData Platform MVP since 2006  Works with SQL Server from 6.5, on BI from 2003  Specialized in Data SolutionArchitecture, Database Design, PerformanceTuning, High- Performance DataWarehousing, BI, Big Data  Very strong developer background  Loves community!  President of UGISS (Italian SQL Server UG) for 11Years, AppDevVG Leader since 2017  Regular Speaker @ SQL Server events  Director SW & Cloud @ Sensoria: http://www.sensoriafitness.com/  E-mail: info@davidemauri.it -Twitter: @mauridb  Blog: http://sqlblog.com/blogs/davide_mauri/default.aspx
  • 3.
    LOVE AT FIRSTSIGHT!  TemporalTables
  • 4.
    THINGSTO KEEP INMIND  Stored interval is half-open: [valid_from, valid_to)  >= valid_fromAND < valid_to  Stored interval is in UTC
  • 5.
    TEMPORALTABLES  Automatically keepstrack of changed data (versioning)  Along with period of validity  Available in all editions of SQL Server (from the Express!)  Available in SQL Azure  ANSI 2011 compliant  Provide native support for temporal queries  Transparent to existing applications (if needed)  Integrated with existing features (eg: Partitioning, Hekaton, ColumnStore)  Integrated with new features (eg: Stretch Database)
  • 6.
    TEMPORAL QUERIES  SQLServer 2016 supports  AS OF <date_time>  FROM <start_date_time>TO <end_date_time>  BETWEEN <start_date_time> AND <end_date_time>  CONTAINED IN (<start_date_time> , <end_date_time>)  ALL  https://docs.microsoft.com/en-us/sql/relational-databases/tables/temporal-tables http://www.ics.uci.edu/~alspaugh/cls/shr/allen.html
  • 7.
    TEMPORALTABLES  Some limitationscompared to “classic” tables  NoTRUNCATETABLE support  INSTEADOF triggers not supported  Temporal tables *can* be ALTERed  A few limitations:  Cannot add a computed columns  Cannot add an Identity column  Versioning can be turned on/off as we wish
  • 8.
    TEMPORALTABLES  SQL 2016:Thereis *no* automatic cleanup of versioning  Stretch Database offer “a sort of” automatic archival (but still no cleaning!)  Tips: https://msdn.microsoft.com/library/mt637341.aspx  SQL vNext – Azure SQL:There *is* an automatic cleanup process of versioning  https://docs.microsoft.com/en-us/azure/sql-database/sql-database-temporal-tables- retention-policy
  • 9.
  • 10.
    TEMPORALTABLES  Temporal querieswith other operators than “AS OF” can be tricky  Especially if you’re joining temporal tables  Rows are not unpacked and then packed back!  Hugh Darwen http://www.dcs.warwick.ac.uk/~hugh/
  • 11.
  • 12.
    ADDITIONAL READS  FirstLook at System-VersionedTemporalTables  http://sqlmag.com/sql-server/first-look-system-versioned-temporal-tables-part-1-creating- tables-and-modifying-data  http://sqlmag.com/sql-server/first-look-system-versioned-temporal-tables-part-2-querying- data-and-optimization-conside  Usage Scenarios  https://docs.microsoft.com/en-us/sql/relational-databases/tables/temporal-table-usage- scenarios  Temporal data (as a general topic)  https://www.amazon.com/Time-Relational-Theory-Second-Management/dp/0128006315  https://www.pluralsight.com/courses/working-with-temporal-data-sql-server
  • 13.
    VOTE ON CONNECT Temporal support is good but can be improved! Help telling Microsoft you what more:  Add SQL Server Engine Support for Interval Queries (Intersection/Overlap and other Allen’s interval algebra relations)  https://connect.microsoft.com/SQLServer/Feedback/Details/780746  TemporalTables: Connect Item Round Up  http://sqlblog.com/blogs/adam_machanic/archive/2016/10/04/temporal-tables-connect-item- round-up.aspx
  • 14.