-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Disable and Re-Enable Change Tracking on Database and Tables.sql
- Loading branch information
1 parent
672b2fb
commit b42586c
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Utility Scripts/Disable and Re-Enable Change Tracking on Database and Tables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |