[MSSQL]禁用触发器

--禁用触发器

declare @Tbl char(20)
declare @Trig char(20)
declare @SQL char(200)
DECLARE c_Trig CURSOR FOR 
 ---取所有触发器
 select object_name(parent_obj) as TblName,[name] as TrigName
 from sysobjects  
 where type='TR'
  and (status & 2048=2048) --状态为“启用”
OPEN c_Trig
FETCH NEXT FROM c_Trig 
INTO @Tbl, @Trig
WHILE @@FETCH_STATUS = 0
BEGIN
 set @Sql='alter table ' + @Tbl + ' disable trigger ' + @Trig
 exec(@sql)    --因SQL Server中表名不能使用变量,故要使用SQL语句
 FETCH NEXT FROM c_Trig 
   INTO @Tbl, @Trig
END
CLOSE c_Trig
DEALLOCATE c_Trig
 

 

你可能感兴趣的:(sql,sql,c,object,server,table)