• 在存储过程中设置某表的触发器是否启用


     
    ALTER  PROCEDURE [dbo].[DisableEnable_Trigger]
    @TableName varchar(50),
    @DisableEnableType VARCHAR(10)
    AS
    /*****************************************************************************************
     **      Input:
    **   @TableName: table to disable/enable trigger
    **   @DisableEnableType in ('Disable', 'Enable')

     **   Exec DisableEnable_Trigger 'OuttblStore', 'Disable'
    **   Exec DisableEnable_Trigger 'OuttblStore', 'Enable'
     **  
    ******************************************************************************************/
    BEGIN
    SET NOCOUNT ON
     --PRINT 'Executing DisableEnable_Trigger...' + @TableName
     DECLARE  @TriggerName  VARCHAR(100)
     DECLARE  @SqlStatement NVARCHAR(200)
     
     -- Get triggers list in cursor
     DECLARE  cursorTriggers CURSOR FOR
     SELECT name FROM sysobjects
      WHERE xtype = 'TR' and parent_obj =
       (SELECT id FROM sysobjects WHERE name = @TableName)

      OPEN cursorTriggers
       FETCH NEXT FROM cursorTriggers INTO @TriggerName
       WHILE @@FETCH_STATUS = 0
       BEGIN
       IF upper(@DisableEnableType) = 'DISABLE'
        SET @SqlStatement = 'ALTER TABLE '+@TableName+' DISABLE TRIGGER ' +@TriggerName
       ELSE
        SET @SqlStatement = 'ALTER TABLE '+@TableName+' ENABLE TRIGGER ' +@TriggerName
     
       --PRINT @SqlStatement
       EXEC sp_executesql @SqlStatement
        
          FETCH NEXT FROM cursorTriggers INTO @TriggerName
       END
       CLOSE cursorTriggers
       DEALLOCATE cursorTriggers

     --PRINT 'Executed DisableEnable_Trigger...' + @TableName+ '.'+@DisableEnableType
    SET NOCOUNT OFF
    END


     

  • 相关阅读:
    mysql中中文乱码问题
    jdbc操作数据库
    PreparedStatement解决sql注入问题
    向mysql数据库中插入大二进制文件和大文本
    Statement及PreparedStatement执行多个sql
    自定义EL函数
    自定义标签
    dom4j操作xml对象
    mysql中中文乱码问题
    jdbc操作数据库
  • 原文地址:https://www.cnblogs.com/huanghai223/p/2144757.html
Copyright © 2020-2023  润新知