Situatie
Mai jos este o procedura ce primeste un pramateru de tip bit si in functie de acesta, da enable sau disble la toti trigerri de pe baza pe care este rulata.
Solutie
— exec EnableDisableTrigger 1
alter Procedure EnableDisableTrigger @check bit =0
— 0 for Disable Triggers
— 1 for Enable Triggers
— Default 0
as
if exists (select * from tempdb..sysobjects where name= ‘##trtemp’ and xtype=’u’)
drop table ##trtemp
declare @maxid int
declare @string varchar(8000)
declare @tbname varchar(100)
declare @trname varchar(100)
Create table ##trtemp (trid int identity(1,1), Table_Name varchar(200))
insert into ##trtemp select name as tbname from sysobjects where id in(select parent_obj from sysobjects where xtype=’tr’)
select @maxid=max(trid) from ##trtemp
while (@maxid>=1)
begin
select @tbname=Table_Name from ##trtemp where trid =@maxid
if @check=0
set @string =’Alter table ‘+ @tbname + ‘ disable trigger all’
if @check=1
set @string =’Alter table ‘+ @tbname + ‘ enable trigger all’
exec (@string)
–print @string
set @maxid = @maxid-1
end
if @check=0
select ‘” TRIGGERS ARE DISABLED “‘
if @check=1
select ‘” TRIGGERS ARE ENABLED “‘
drop table ##trtemp
Leave A Comment?