2015-06-29 23 views

risposta

9
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

3

Un altro modo di elencare le tabelle temporali con le loro tabelle di cronologia insieme è dato in questo tutorial SQL come List Temporal and History Tables in a SQL Server Database

select 
t.object_id, 
t.name, 
t.temporal_type, 
t.temporal_type_desc, 
h.object_id, 
h.name, 
h.temporal_type, 
h.temporal_type_desc 
from sys.tables t 
inner join sys.tables h on t.history_table_id = h.object_id 
0

Questa query vi darà le tabelle di sistema di versione, le tabelle di cronologia associati, il criterio di conservazione, e se il criterio di conservazione è abilitato a livello di database.

From Microsoft Docs

SELECT DB.is_temporal_history_retention_enabled, 
SCHEMA_NAME(T1.schema_id) AS TemporalTableSchema, 
T1.name as TemporalTableName, SCHEMA_NAME(T2.schema_id) AS HistoryTableSchema, 
T2.name as HistoryTableName,T1.history_retention_period, 
T1.history_retention_period_unit_desc 
FROM sys.tables T1 
OUTER APPLY (select is_temporal_history_retention_enabled from sys.databases 
where name = DB_NAME()) AS DB 
LEFT JOIN sys.tables T2 
ON T1.history_table_id = T2.object_id WHERE T1.temporal_type = 2 
0

Ecco una semplice risposta alla domanda di base originale:

SELECT * 
FROM sys.tables 
WHERE name = 'MyTable' 
    AND schema_id = SCHEMA_ID('dbo') 
    AND temporal_type_desc = 'SYSTEM_VERSIONED_TEMPORAL_TABLE' 

E qui è una query simile alla ricerca di l'attuale sistema gestito tabella della cronologia:

SELECT h.* FROM sys.tables p 
INNER JOIN sys.tables h 
    ON p.history_table_id = h.object_id 
WHERE p.name = 'MyTable' 
    AND p.schema_id = SCHEMA_ID('dbo') 
    AND p.temporal_type_desc = 'SYSTEM_VERSIONED_TEMPORAL_TABLE';