Home > Enterprise >  Query to check the table is temporal
Query to check the table is temporal

Time:10-02

how to check if the table is temporal from c#? How to build the query. I need to get into a variable whether a table is versioned.

Regards

CodePudding user response:

You can use something like this:

SELECT t.name, t.history_table_id, t.temporal_type, t.temporal_type_desc
FROM sys.tables t

The t.temporal_type / temporal_type_desc will show you whether or not the table is "temporal-enabled", and if it is, history_table_id will give you the table_id for the history table.

CodePudding user response:

You can also use the OBJECTPROPERTY function

SELECT OBJECTPROPERTY(OBJECT_ID(N'dbo.YourTable'), 'TableTemporalType'); 

Which returns

  • 0 = non-temporal table
  • 1 = history table for system-versioned table
  • 2 = system-versioned temporal table

Or NULL if no such table that you have permissions to see.

  • Related