Back to OIM Explorer

dbo.QBM_PDatabaseTriggerDisable

Stored ProcedureSQL_STORED_PROCEDURESandbox DB

Stored Procedure.

Source: sandbox-db sys.sql_modules

Source size: 2.501 characters

Interpretation

  • Database routine. Review parameters, called procedures, DBQueue inserts, and QBM_PJobCreate helper calls before assuming side effects.

Relations

  • No extracted relations.

Typed Edges

  • references source dbo.QBM_FCVIntToString source text reference
  • references source dbo.QBM_FGISessionErrorRethrow source text reference
  • references source dbo.QBM_PExecuteSQLWithRetry_LLP source text reference
  • references source dbo.QBM_PJournal source text reference
  • references source dbo.QBM_PSessionErrorAdd source text reference

Complete Source

SQL104 lines
1CREATE PROCEDURE QBM_PDatabaseTriggerDisable(2  @TriggerPattern nvarchar(64) = '%',3  @UseTriggerPatternForNotLike BIT = 04)5AS6BEGIN7  DECLARE @musterTrigger nvarchar(1024)8  DECLARE @SQLcmd nvarchar(max)9  DECLARE @Triggername nvarchar(64)10  DECLARE @elements QBM_YCursorBuffer11  DECLARE @ElementCount int12  DECLARE @ElementIndex int13  DECLARE @JournalMessage nvarchar(1000)14  DECLARE @DebugSwitch int = 015  DECLARE @DebugLevel varchar(1) = 'I'16  DECLARE @MessageType varchar(1) = 'W'17  BEGIN TRY18    SET nocount19      ON20    SELECT @musterTrigger = N 'disable trigger %triggername% on database '21    INSERT INTO @elements(LongIdent1)22    SELECT23      DISTINCT CASE @TriggerPattern24      WHEN '%' THEN25      'all'26    ELSE '"' + t.name + '"'27    END AS Triggername28    FROM sys.triggers t29    WHERE30      parent_class = 0 AND is_ms_shipped = 0 AND t.is_disabled = 0 AND(@UseTriggerPatternForNotLike = 0 AND t.name LIKE @TriggerPattern OR @UseTriggerPatternForNotLike31    = 1 AND t.name NOT LIKE @TriggerPattern)32    ORDER BY 133    SELECT @ElementCount = @@ROWCOUNT34    SELECT @ElementIndex = 135    WHILE @ElementIndex <= @ElementCount36    BEGIN37      SELECT TOP 1 @TriggerName = bu.LongIdent138      FROM @elements bu39      WHERE40        bu.ElementIndex = @ElementIndex41      SELECT42        @SQLcmd = replace(@musterTrigger,43        '%triggername%',44        @Triggername)45      IF @DebugSwitch > 046      BEGIN47        print @SQLcmd48      END49      EXEC QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQLcmd,50        @LockTimeout_ms = 2500,51        @MaxWaitTimeForLock_s = 10,52        @ProcIDForJournal = @@procid,53        @HandleErrorSilent = 0,54        @ExecuteWithTransact = 055      SELECT @ElementIndex += 156    END57    IF @ElementCount > 0 AND EXISTS(58      SELECT TOP 1 159      FROM sys.objects o60      WHERE61        o.name = 'QBM_PJournal' AND type = 'P')62    BEGIN63      SELECT64        @JournalMessage = '#LDS#System elements modified by {0}, pattern {1}, elements affected {2}.|' + isnull(OBJECT_NAME(@@procid),65        '') + '|' + @TriggerPattern + '|' + dbo.QBM_FCVIntToString(@ElementCount) + '|'66      IF NOT EXISTS(67        SELECT TOP 1 168        FROM DialogDatabase69        WHERE70          IsMainDatabase = 1 AND UpdatePhase <> 0) AND NOT EXISTS(71      SELECT TOP 1 172      FROM sys.tables t73        WITH(readpast)74      JOIN sys.columns c75        WITH(readpast)76        ON t.object_id = c.object_id77      WHERE78        t.name = 'DialogDatabase' AND c.name = 'InitialMigrationRunning')79      BEGIN80        EXEC QBM_PJournal @JournalMessage,81          @@procid,82          @MessageType,83          @DebugLevel84      END85      ELSE86      BEGIN87        EXEC QBM_PJournal @JournalMessage,88          @@procid,89        'I',90        'I'91      END92    END93  END TRY94  BEGIN CATCH95    EXEC QBM_PSessionErrorAdd DEFAULT96    DECLARE @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow()97    RAISERROR(@Rethrow,98    18,99    1)100      WITH NOWAIT101  END CATCH102  endLabel:103  RETURN104END
Open raw exported source
SQL ยท Raw17 lines
1  create   procedure QBM_PDatabaseTriggerDisable (@TriggerPattern nvarchar(64) = '%' , @UseTriggerPatternForNotLike bit = 0 ) as begin declare @musterTrigger2 nvarchar(1024) declare @SQLcmd nvarchar(max) declare @Triggername nvarchar(64) declare @elements QBM_YCursorBuffer declare @ElementCount int declare @ElementIndex3 int declare @JournalMessage nvarchar(1000) declare @DebugSwitch int = 0 declare @DebugLevel varchar(1) = 'I' declare @MessageType varchar(1) = 'W' BEGIN4 TRY set nocount on select @musterTrigger = N'disable trigger %triggername% on database ' insert into @elements(LongIdent1) select distinct case @TriggerPattern5 when '%' then 'all' else '"' + t.name + '"' end as Triggername from sys.triggers t  where parent_class = 0  and is_ms_shipped = 0  and t.is_disabled =6 0 and ( @UseTriggerPatternForNotLike = 0 and t.name like @TriggerPattern or @UseTriggerPatternForNotLike = 1 and t.name not like @TriggerPattern ) order7 by 1 select @ElementCount = @@ROWCOUNT select @ElementIndex = 1 while @ElementIndex <= @ElementCount begin select top 1 @TriggerName = bu.LongIdent1 from8 @elements bu where bu.ElementIndex = @ElementIndex select @SQLcmd = replace(@musterTrigger, '%triggername%', @Triggername) if @DebugSwitch > 0 begin print9 @SQLcmd end  exec QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQLcmd , @LockTimeout_ms = 2500  , @MaxWaitTimeForLock_s = 10  , @ProcIDForJournal = @@procid10 , @HandleErrorSilent = 0 , @ExecuteWithTransact = 0 select @ElementIndex += 1 end  if @ElementCount > 0 and exists (select top 1 1 from sys.objects o 11where o.name = 'QBM_PJournal' and type = 'P' ) begin select @JournalMessage = '#LDS#System elements modified by {0}, pattern {1}, elements affected {2}.|'12 + isnull(OBJECT_NAME(@@procid), '') + '|' + @TriggerPattern + '|' + dbo.QBM_FCVIntToString(@ElementCount) + '|'  if not exists (select top 1 1 from DialogDatabase13 where IsMainDatabase = 1 and UpdatePhase <> 0) and not exists (select top 1 1 from sys.tables t with (readpast) join sys.columns c with (readpast) on 14t.object_id = c.object_id where t.name = 'DialogDatabase' and c.name = 'InitialMigrationRunning' ) begin exec QBM_PJournal @JournalMessage, @@procid, @MessageType15, @DebugLevel end else begin  exec QBM_PJournal @JournalMessage, @@procid, 'I', 'I' end end END TRY BEGIN CATCH exec QBM_PSessionErrorAdd default declare16 @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow() RAISERROR (@Rethrow, 18, 1) WITH NOWAIT END CATCH endLabel:  return end 17