{"id":14721,"date":"2016-01-11T09:30:00","date_gmt":"2016-01-11T17:30:00","guid":{"rendered":""},"modified":"2024-01-22T22:52:26","modified_gmt":"2024-01-23T06:52:26","slug":"effortlessly-analyze-data-history-using-temporal-tables-2","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/sql-server\/blog\/2016\/01\/11\/effortlessly-analyze-data-history-using-temporal-tables-2\/","title":{"rendered":"Effortlessly Analyze Data History Using Temporal Tables"},"content":{"rendered":"
Real data sources are never static; critical business information changes over time and important decisions often rely on insights that analysts get from evolving data.<\/p>\n
Users who track data history aim to answer fundamental questions: How did data look in a specific point in time in the past (yesterday, a month ago, a year ago, etc.)?, what changes have been made?, and when and what were the dominant trends in a specific period of time? Without proper support in the database, however, questions like these have never been easy to answer.<\/p>\n
Temporal Tables are a new feature in SQL Server 2016<\/a>, designed to be the ultimate productivity tool for developing or migrating applications that provide insights from historical data. Temporal Tables allow you to track the full history of changes without additional code and let you focus your data analysis on a specific point in time in a very simple and efficient way.<\/p>\n Temporal Tables keep data closely related to time context<\/strong> so that stored facts can be interpreted as valid only within the specific period<\/strong>. They are also referred to as a system-versioned temporal table<\/strong>, because the period of validity for each row is automatically maintained by the system (i.e. database engine).<\/p>\n Depending on a scenario, you can either create new system-versioned temporal tables or extend existing ones with temporal attributes.<\/p>\n When the data in a temporal table is modified, version history is built automatically and transparently without additional action from the end user or application. This property makes Temporal Tables an obvious choice when adding data auditing to existing applications because it is not necessary to change how they interact with the database in order to modify or read the latest (actual) state of data.<\/p>\n With Temporal Tables, historical data is just one query away, which gives you very efficient point-in-time analysis without additional latency.<\/p>\n The diagram below depicts a typical user workflow with Temporal Tables:<\/p>\n To get started with Temporal Tables, download the AdventureWorks Database for SQL Server 2016 CTP3<\/a> with script samples and follow the instructions in the folder \u201cTemporal.”<\/p>\n To learn the different ways to create Temporal Tables and work with them in your applications, check out Getting started with system-versioned Temporal Tables at MSDN<\/a>.<\/p>\n Temporal Tables can be used in a wide set of scenarios when you need to track data history. We strongly recommend it in the following use cases due to the huge productivity benefits:<\/p>\n For detailed descriptions of supported scenarios, refer to Temporal Table usage scenarios on MSDN<\/a>.<\/p>\n Temporal Tables are a huge productivity booster for SQL Server developers because they simplify every phase in the data lifecycle, from the object creation through schema evolution, data modification, data analysis to security. The image below summarizes all benefits for users.<\/p>\n A Temporal Table is a configuration that includes two user tables: current<\/strong>, keeping actual (latest) row versions, and history<\/strong>, storing previous versions for every row in case it has ever changed or been deleted. Any operation that inserts new rows affects only the current table during which the database automatically records the period start time based on the begin time of the transaction. Additional overhead of the insert operation is negligible, compared to inserts for non-Temporal Tables.<\/p>\n During the update or delete operations, previous row versions are automatically moved to the history table with the end of period updated to the begin time of the transaction that initiated change in the current table. That operation is referred to as \u201csystem-versioning\u201d and it occurs as part of the same transaction that modifies the current table.<\/p>\n System-versioning adds overhead to update\/delete operations compared to the non-temporal case because it actually performs two operations. However, overhead is less than in any custom solution users build for temporal data handling (triggers, stored procedures, and application logic).<\/p>\n Querying of current data does not differ from the non-temporal case and it does not introduce any performance overhead either. There are several modes of querying historical data with the FOR SYSTEM_TIME clause. During the processing of query with FOR SYSTEM_TIME, SQL Server transparently adds a union between the current and history tables and propagates temporal predicates to filter data based on their period of validity.<\/p>\n The size of the history table depends on the application DML pattern (insert vs. update\/delete) and period of time during which system-versioning was active, but in general, Temporal Tables tend to increase database size more than regular tables. Therefore, it is strongly recommended that you plan for retention of historical data and perform periodic data clean-ups.<\/p>\n Temporal Tables on MSDN<\/a><\/p>\n Getting started with Temporal Tables<\/a><\/p>\n Temporal Tables on Channel 9<\/a><\/p>\n Temporal Table usage scenarios<\/a><\/p>\n Manage retention of historical data in system-versioned Temporal Tables<\/a><\/p>\n System-versioned Temporal Tables with memory-optimized tables<\/a><\/p>\n See the other posts in the SQL Server 2016 blogging series<\/a>.<\/p>\nGetting started with Temporal Tables<\/h1>\n
<\/a><\/p>\nTypical scenarios<\/h1>\n
<\/a><\/p>\n\n
Effectiveness of using Temporal Tables<\/h1>\n
<\/a><\/p>\n\n
How Temporal Tables work<\/h1>\n
<\/a><\/p>\n
<\/a><\/p>\nLearn more<\/h1>\n