You can suppress a trigger by checking for a temporary table. The code for which the trigger must be suppressed must create a temporary table (say #suppress_trigger). In your trigger, check for the presence of this temp table and return. Example:
CREATE TABLE [dbo].[dummy]( [Id] [int] IDENTITY(1,1) NOT NULL, [Val] [char](1) NULL) --create a history table which gets populated through trigger CREATE TABLE [dbo].[dummy_hist]( [Id] [int] NULL, [Val] [char](1) NULL) CREATE TRIGGER [dbo].[trig_Insert] ON [dbo].[dummy] AFTER INSERT AS BEGIN SET NOCOUNT ON; if OBJECT_ID('tempdb..#Dummy_escape_trig') is not NULL RETURN INSERT INTO dummy_hist SELECT * FROM inserted END --Proc for which trigger needs to be suppressed CREATE PROCEDURE [dbo].[ins_dummy] @val AS CHAR(1) AS BEGIN SET NOCOUNT ON; CREATE TABLE #Dummy_escape_trig (id int) INSERT INTO dummy VALUES(@val) END
source share