Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why we require temporal table in SQL Server 2016 as we have CDC or CT?

What advantages do Temporal Tables have over Change Data Capture or Change Tracking in SQL Server?

like image 695
Kannan Kandasamy Avatar asked Aug 26 '16 11:08

Kannan Kandasamy


People also ask

Which of the following are a must have for temporal tables in SQL Server?

A temporal table must have a primary key defined in order to correlate records between the current table and the history table, and the history table can't have a primary key defined. The SYSTEM_TIME period columns used to record the ValidFrom and ValidTo values must be defined with a datatype of datetime2.

Why do we need change data capture?

Benefits of Change Data Capture Ultimately, CDC will help your organization obtain greater value from your data by allowing you to integrate and analyze data faster—and use fewer system resources in the process.

Are temporal tables good?

With minimal setup, these help answer so many questions we get, I can see plenty of both data/business use cases ("how many registrants did this conference have 90, 60, and 30 days before the event") but also many schema or framework level audit questions as well.


1 Answers

CDC and change tracking really are not intended to solve historical data problems. As the names imply, change tracking or CDC tells you things changed and what the changes were. You can choose to do what you want with it and that may include persisting the data somewhere if you need to keep historical data. This includes capturing, tweaking (e.g. add some kind of timestamp to the schema), storing and managing the data and associated processes. It's workable but the effort is non-trivial and on-going.

Temporal databases provide native capabilities to manage historical data including query semantics. You have to roll your own potentially complex queries to get the same capabilities in a DB that has temporal capabilities (e.g. what would your query look like to answer the question: what was the average temperature across the 42 type-MCC2 sensors in sector C at 3pm on Aug 28, 2016?). This assumes you already have the data in a queryable format.

There are lots of good write ups on why temporal that you should check out: Why do we need a temporal database?

like image 79
SQLmojoe Avatar answered Sep 22 '22 11:09

SQLmojoe