Das folgende Skript kann verwendet werden, um alle Trigger in der SQL Server-Datenbank zu deaktivieren.
USE [Datenbank]
GO
DECLARE @TriggerName AS VARCHAR(500)
DECLARE @TableName AS VARCHAR(500)
DECLARE @SchemaName AS VARCHAR(100)
--Deaktiviert alle Trigger in einer Datenbank in 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='Trigger deaktivieren ' + @TriggerName +' ON '+@SchemaName+'.'+@TableName
EXEC (@SQL)
PRINT 'Trigger ::' + @TriggerName + 'ist deaktiviert auf '+@SchemaName+'.'+@TableName
PRINT @SQL
FETCH Next FROM DisableTrigger INTO @TableName,@SchemaName, @TriggerName
END
CLOSE DisableTrigger
DEALLOCATE DisableTrigger
Um zu überprüfen, ob alle Trigger in SQL korrekt deaktiviert sind Server-Datenbank, verwenden Sie die folgende Abfrage
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
UND trg.is_disabled=1 – Verwenden Sie diesen Filter, um deaktivierte Trigger zu erhalten