Change tracking help SQL
No edit summary |
(Automatically adding template at the end of the page.) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
This is the stored procedure for removing all change tracking on the current database:{{Pre2|<nowiki> | |||
CREATE PROCEDURE [dbo].[spTurnOffChangeTracking] | CREATE PROCEDURE [dbo].[spTurnOffChangeTracking] | ||
AS | AS | ||
Line 28: | Line 28: | ||
SET CHANGE_TRACKING = OFF | SET CHANGE_TRACKING = OFF | ||
END | END | ||
</nowiki>}} | </nowiki>}}The view for listing change tracked tables:{{Pre2|<nowiki> | ||
CREATE VIEW [dbo].[ChangeTrackedTables] | CREATE VIEW [dbo].[ChangeTrackedTables] | ||
AS | AS | ||
Line 38: | Line 38: | ||
</nowiki>}} | </nowiki>}} | ||
[[Category:SQL]] | [[Category:SQL]] | ||
{{Edited|July|12|2024}} |
Latest revision as of 15:28, 10 February 2024
This is the stored procedure for removing all change tracking on the current database:
CREATE PROCEDURE [dbo].[spTurnOffChangeTracking] AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Turn off change tracking for the tables, one by one DECLARE @name VARCHAR(100) DECLARE @command VARCHAR(400) DECLARE db_cursor CURSOR FOR SELECT Table_name FROM ChangeTrackedTables OPEN db_cursor FETCH NEXT FROM db_cursor INTO @name WHILE @@FETCH_STATUS = 0 BEGIN set @command = 'ALTER TABLE ' + @name + ' DISABLE CHANGE_TRACKING' exec(@command) FETCH NEXT FROM db_cursor INTO @name END CLOSE db_cursor DEALLOCATE db_cursor -- Turn off change tracking for the database ALTER DATABASE Kubik SET CHANGE_TRACKING = OFF END
The view for listing change tracked tables:
CREATE VIEW [dbo].[ChangeTrackedTables] AS SELECT TOP (100) PERCENT s.name AS Schema_name, t.name AS Table_name FROM sys.change_tracking_tables AS ctt INNER JOIN sys.tables AS t ON t.object_id = ctt.object_id INNER JOIN sys.schemas AS s ON s.schema_id = t.schema_id ORDER BY Schema_name, Table_name
This page was edited more than 11 months ago on 02/10/2024. What links here