USE [ Banco de dados]
GO
DECLARE @TriggerName AS VARCHAR(500)
-- Elimina ou exclui todos os gatilhos em um banco de dados no SQL Server
DECLARE DropTrigger CURSOR FOR
SELECT TRG .name AS TriggerName
FROM sys.triggers TRG
INNER JOIN sys.tables TBL
ON TBL.OBJECT_ID =TRG.parent_id
OPEN DropTrigger
FETCH Next FROM DropTrigger INTO @TriggerName
WHILE @@FETCH_STATUS =0
BEGIN
DECLARE @SQL VARCHAR(MAX)=NULL
SET @SQL='Drop Trigger ' + @TriggerName
PRINT 'Trigger ::' + @TriggerName
+ ' Eliminado com sucesso'
EXEC (@SQL)
PRINT @SQL
FETCH Next FROM DropTrigger INTO @TriggerName
END
FECHAR DropTrigger
DESALOCAR DropTrigger