How to check if change tracking is enabled
Asked Answered
F

1

32

I'm trying to determine if Change Tracking is already enabled on my database before I run the ALTER DATABASE command to enable it. I am trying to prevent errors with these scripts if run multiple times.

I checked in sys.databases and sys.dm_tran_commit_table but was unable to find what I was looking for.

Fcc answered 16/4, 2012 at 18:48 Comment(0)
F
53

You can use this query:

SELECT * 
FROM sys.change_tracking_databases 
WHERE database_id=DB_ID('MyDatabase')
Filum answered 16/4, 2012 at 18:53 Comment(3)
So I was unfamiliar with Change Tracking and found this question searching about Change Data Capture (CDC). For others who happen to be here, the equivalent question/answer for CDC is found here SELECT s.name AS Schema_Name, tb.name AS Table_Name , tb.object_id, tb.type, tb.type_desc, tb.is_tracked_by_cdc FROM sys.tables tb INNER JOIN sys.schemas s on s.schema_id = tb.schema_id WHERE tb.is_tracked_by_cdc = 1Lands
To check the current database, you can use SELECT * FROM sys.change_tracking_databases WHERE database_id=DB_ID() (no parameter)(Taishataisho
to help others, if you need to enable / disable this configuration you can use: ALTER DATABASE MyDatabaseName SET CHANGE_TRACKING = ONImpermissible

© 2022 - 2025 — McMap. All rights reserved.