Wednesday, March 11, 2009

Cursor : Disable All Triggers on a Database

CREATE PROCEDURE [dbo].[DisableAllTriggers]
AS
DECLARE @string VARCHAR(8000)
DECLARE @tableName NVARCHAR(500)
DECLARE cur CURSOR
FOR SELECT name AS tbname FROM sysobjects WHERE id IN(SELECT parent_obj FROM sysobjects WHERE xtype=‘tr’)
OPEN cur
FETCH next FROM cur INTO @tableName
WHILE @@fetch_status = 0
BEGIN
SET @string =‘Alter table ’+ @tableName + ‘ Disable trigger all’
EXEC (@string)
FETCH next FROM cur INTO @tableName
END
CLOSE cur
DEALLOCATE cur
GO
—-To execute the SP
EXEC [DisableAllTriggers]

Reference : Pinal Dave (http://blog.SQLAuthority.com)

No comments: