Het onderstaande script kan worden gebruikt om alle triggers in de SQL Server-database uit te schakelen.
GEBRUIK [Database]
GO
DECLARE @TriggerName AS VARCHAR(500)
DECLARE @TableName AS VARCHAR(500)
DECLARE @SchemaName AS VARCHAR(100)
--Alle triggers in een database in SQL Server uitschakelen
DECLARE DisableTrigger CURSOR FOR
SELECT TBL.name AS TableName,
Schema_name(TBL.schema_id) AS Table_SchemaName,
TRG .name AS TriggerName
VAN sys.triggers TRG
INNER WORDT LID SYS.tables TBL
OP 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
TERWIJL @@FETCH_STATUS =0
BEGIN
VERKLAREN @SQL VARCHAR(MAX)=NU LL
SET @SQL='Trigger uitschakelen ' + @TriggerName +' ON '+@SchemaName+'.'+@TableName
EXEC (@SQL)
PRINT 'Trigger ::' + @TriggerName + 'is uitgeschakeld op '+@SchemaName+'.'+@TableName
PRINT @SQL
FETCH Volgende FROM DisableTrigger INTO @TableName,@SchemaName, @TriggerName
END
CLOSE DisableTrigger
DEALLOCATE DisableTrigger
Controleren of alle triggers correct zijn uitgeschakeld in SQL Serverdatabase, gebruik onderstaande query
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 WORD LID van sys.tables TBL
OP TBL.OBJECT_ID =TRG.parent_id
AND trg.is_disabled=1 --gebruik dit filter om uitgeschakelde triggers te krijgen