O script abaixo pode ser usado para desabilitar todos os triggers no Banco de Dados SQL Server.
USE [Banco de dados]
GO
DECLARE @TriggerName AS VARCHAR(500)
DECLARE @TableName AS VARCHAR(500)
DECLARE @SchemaName AS VARCHAR(100)
--Desabilitar todos os gatilhos em um banco de dados no SQL Server
DECLARE DisableTrigger CURSOR FOR
SELECT TBL.name AS TableName,
Schema_name(TBL.schema_id) AS Table_SchemaName,
TRG .name AS TriggerName
FROM sys.triggers TRG
INNER JOIN sys.tables TBL
ON TBL.OBJECT_ID =TRG.parent_id
AND TRG.is_disabled=0
AND TBL.is_ms_shipped=0
OPEN DisableTrigger
FETCH Next FROM DisableTrigger INTO @TableName,@SchemaName,@TriggerName
WHILE @@FETCH_STATUS =0
BEGIN
DECLARE @SQL VARCHAR(MAX)=NU LL
SET @SQL='Desabilitar Trigger ' + @TriggerName +' ON '+@SchemaName+'.'+@TableName
EXEC (@SQL)
PRINT 'Trigger ::' + @TriggerName + 'está desabilitado em '+@SchemaName+'.'+@TableName
PRINT @SQL
FETCH Next FROM DisableTrigger INTO @TableName,@SchemaName, @TriggerName
END
CLOSE DisableTrigger
DEALLOCATE DisableTrigger
Para verificar se todos os gatilhos estão desabilitados corretamente no SQL Banco de dados do servidor, use a consulta abaixo
SELECT TBL.name AS TableName,
Schema_name(TBL.schema_id) AS Table_SchemaName,
TRG.name AS TriggerName,
TRG. parent_class_desc,
CASE
WHEN TRG.is_disabled =0 THEN 'Enable'
ELSE 'Disable'
END AS TRG_Status
FROM sys.triggers TRG
INNER JOIN sys.tables TBL
ON TBL.OBJECT_ID =TRG.parent_id
AND trg.is_disabled=1 --use este filtro para obter Disabled Triggers