0

How can I determine when change tracking was enabled on a table in a SQL database?

Assume that this table has a regular cleanup routine, which means that looking at the oldest record in the change tracking table won't provide the right answer.

2
  • That would only work if Change Data Capture was enabled. It is not - only Change Tracking is enabled. Change Data Capture <> Change Tracking. technet.microsoft.com/en-us/library/cc280519(v=sql.105).aspx
    – dev_etter
    Aug 8, 2014 at 2:49
  • The customer didn't know CT was enabled, they don't even know if they have any current use/business need for the CT, and I wanted to let them know when it was originally enabled (which was almost 4 years ago). It may help them investigate its original purpose, and whether they can turn it off. The tables being tracked have heavy daily production DML processing.
    – dev_etter
    Aug 8, 2014 at 15:18

1 Answer 1

1
  1. Run the following query in the context of the database in question in order to get the Change Tracking table names used on the database. (Query via Kendra Little on BrentOzar.com)

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
    GO
        select sct1.name as CT_schema,
        sot1.name as CT_table,
        ps1.row_count as CT_rows,
        ps1.reserved_page_count*8./1024. as CT_reserved_MB,
        sct2.name as tracked_schema,
        sot2.name as tracked_name,
        ps2.row_count as tracked_rows,
        ps2.reserved_page_count*8./1024. as tracked_base_table_MB,
        change_tracking_min_valid_version(sot2.object_id) as min_valid_version
    FROM sys.internal_tables it
    JOIN sys.objects sot1 on it.object_id=sot1.object_id
    JOIN sys.schemas AS sct1 on
        sot1.schema_id=sct1.schema_id
    JOIN sys.dm_db_partition_stats ps1 on
        it.object_id = ps1. object_id
        and ps1.index_id in (0,1)
    LEFT JOIN sys.objects sot2 on it.parent_object_id=sot2.object_id
    LEFT JOIN sys.schemas AS sct2 on
        sot2.schema_id=sct2.schema_id
    LEFT JOIN sys.dm_db_partition_stats ps2 on
        sot2.object_id = ps2. object_id
        and ps2.index_id in (0,1)
    WHERE it.internal_type IN (209, 210);
    GO
    
  2. Find the create_date for the change_tracking table(s) found in the first result set by querying sys.internal_tables in the context of the change tracking database.

    SELECT * FROM sys.internal_tables;
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.