With SQL Server 2016 supporting Temporal Tables I wonder if there is a way to determine if a table is currently temporal? Something like
select * from sys.objects where object_id('dbo.MyTable', 'u') = parent_object_id and type_desc = "SYSTEM_VERSIONED"
tables there are specific columns (temporal_type and temporal_type_desc and history_table_id) to identify whether a table is system-versioned temporal table or history table. Using these columns, you can easily get the list of all the temporal current tables and the history tables and get the list of such tables.
Temporal tables (also known as system-versioned temporal tables) are a database feature that brings built-in support for providing information about data stored in the table at any point in time, rather than only the data that is correct at the current moment in time.
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.
SELECT temporal_type FROM sys.tables WHERE object_id = OBJECT_ID('dbo.MyTable', 'u')
0 = NON_TEMPORAL_TABLE
1 = HISTORY_TABLE
2 = SYSTEM_VERSIONED_TEMPORAL_TABLE
Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With