kreta/Kreta.DataAccess.Migrations/Scripts/Archive/20170801122050_KRETA_2449_1/DisableAsyncAuditTriggers.sql
2024-03-13 00:33:46 +01:00

50 lines
No EOL
1 KiB
Transact-SQL

DECLARE trCursor CURSOR FOR
SELECT OBJECT_NAME(parent_id) AS tableName, name as triggerName
FROM sys.triggers
WHERE name like 'tr%Log'
DECLARE
@tableName nvarchar(100),
@triggerName nvarchar(100),
@sql nvarchar(max)
OPEN trCursor
FETCH NEXT FROM trCursor INTO @tableName, @triggerName
WHILE @@FETCH_STATUS = 0 BEGIN
SET @sql = 'DISABLE TRIGGER ' + @triggerName + ' ON ' + @tableName + ';'
EXEC sys.sp_executesql @sql
FETCH NEXT FROM trCursor INTO @tableName, @triggerName
END
CLOSE trCursor
DEALLOCATE trCursor
GO
DECLARE trCursor CURSOR FOR
SELECT OBJECT_NAME(parent_id) AS tableName, name as triggerName
FROM sys.triggers
WHERE name like 'tr_AsyncAudit%'
DECLARE
@tableName nvarchar(100),
@triggerName nvarchar(100),
@sql nvarchar(max)
OPEN trCursor
FETCH NEXT FROM trCursor INTO @tableName, @triggerName
WHILE @@FETCH_STATUS = 0 BEGIN
SET @sql = 'DISABLE TRIGGER ' + @triggerName + ' ON ' + @tableName + ';'
EXEC sys.sp_executesql @sql
FETCH NEXT FROM trCursor INTO @tableName, @triggerName
END
CLOSE trCursor
DEALLOCATE trCursor
GO