Skip to content

Commit

Permalink
Create Disable and Re-Enable Change Tracking on Database and Tables.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
EitanBlumin committed Mar 21, 2024
1 parent 672b2fb commit b42586c
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

-- Generate disable / enable commands at the database level:
SELECT DatabaseName = DB_NAME()
, DisableCmd = CONCAT(N'ALTER DATABASE ', QUOTENAME(DB_NAME()), N' SET CHANGE_TRACKING = OFF;')
, EnableCmd = CONCAT(N'ALTER DATABASE ', QUOTENAME(DB_NAME()), N' SET CHANGE_TRACKING = ON (CHANGE_RETENTION = ', retention_period, N' ', retention_period_units_desc, N', AUTO_CLEANUP = ', CASE is_auto_cleanup_on WHEN 1 THEN N'ON' ELSE N'OFF' END, N');')
, *
FROM sys.change_tracking_databases
WHERE database_id = DB_ID()

-- Generate disable / enable commands at the table level:
select TableName = object_name(object_id)
, DisableCmd = CONCAT(N'USE ', QUOTENAME(DB_NAME()), N'; ALTER TABLE ',object_name(object_id), ' DISABLE CHANGE_TRACKING;')
, EnableCmd = CONCAT(N'USE ', QUOTENAME(DB_NAME()), N'; ALTER TABLE ',object_name(object_id), ' ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = ', CASE is_track_columns_updated_on WHEN 1 THEN N'ON' ELSE N'OFF' END, N');')
, *
from sys.change_tracking_tables

0 comments on commit b42586c

Please sign in to comment.