events that get executed during a DML statement execution
DECLARE @TriggerTableName NVARCHAR(500)
DECLARE DisableTriggerCursor CURSOR
FOR
(
SELECT NAME AS TableName
FROM sysobjects
WHERE id IN (
SELECT parent_obj
FROM sysobjects
WHERE xtype = 'tr'
)
)
OPEN DisableTriggerCursor
FETCH NEXT
FROM DisableTriggerCursor
INTO @TriggerTableName
WHILE @@fetch_status = 0
BEGIN
SET @DisableTriggerCommand = N'ALTER TABLE ' + @TriggerTableName + ' ENABLE TRIGGER ALL'
PRINT 'Print ' + @DisableTriggerCommand + CHAR(13)
EXECUTE sp_executesql @DisableTriggerCommand
FETCH NEXT
FROM DisableTriggerCursor
INTO @TriggerTableName
END
CLOSE DisableTriggerCursor
DEALLOCATE DisableTriggerCursor
Copy, paste, run as mention below .
DECLARE @DisableTriggerCommand NVARCHAR(4000)DECLARE @TriggerTableName NVARCHAR(500)
DECLARE DisableTriggerCursor CURSOR
FOR
(
SELECT NAME AS TableName
FROM sysobjects
WHERE id IN (
SELECT parent_obj
FROM sysobjects
WHERE xtype = 'tr'
)
)
OPEN DisableTriggerCursor
FETCH NEXT
FROM DisableTriggerCursor
INTO @TriggerTableName
WHILE @@fetch_status = 0
BEGIN
SET @DisableTriggerCommand = N'ALTER TABLE ' + @TriggerTableName + ' ENABLE TRIGGER ALL'
PRINT 'Print ' + @DisableTriggerCommand + CHAR(13)
EXECUTE sp_executesql @DisableTriggerCommand
FETCH NEXT
FROM DisableTriggerCursor
INTO @TriggerTableName
END
CLOSE DisableTriggerCursor
DEALLOCATE DisableTriggerCursor
No comments :
Post a Comment