Back to OIM Explorer

dbo.QBM_PTriggerWatchCreate

Stored ProcedureSQL_STORED_PROCEDURESandbox DB

Stored Procedure.

Source: sandbox-db sys.sql_modules

Source size: 9.937 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_FCVDatetimeToString source text reference
  • references source dbo.QBM_FCVDatetimeToStringUTC source text reference
  • references source dbo.QBM_FGIConfigparmValue source text reference
  • references source dbo.QBM_FGISessionContext source text reference
  • references source dbo.QBM_FGISessionErrorRethrow source text reference
  • references source dbo.QBM_FSQBufferConfigSaveOrigin source text reference
  • references source dbo.QBM_FSQTriggerDef source text reference
  • references source dbo.QBM_FSQTriggerPartCEF source text reference
  • references source dbo.QBM_FSQTriggerSplittedLookup source text reference
  • references source dbo.QBM_FSQTriggerWatchSemaphor source text reference
  • references source dbo.QBM_FSQTriggerWatchTable source text reference
  • references source dbo.QBM_FSQTriggerWatchXIsInEffect source text reference
  • references source dbo.QBM_FSQTriggerWatchXOrigin source text reference
  • references source dbo.QBM_FSQWatchRevision source text reference
  • references source dbo.QBM_FSQXDateSubItemUpdate source text reference
  • references source dbo.QBM_FSQXMarkedForDeletionChg source text reference
  • references source dbo.QBM_PDebug 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
  • references source dbo.QBM_PSQLCreate source text reference
  • references source dbo.QBM_PTriggerDrop source text reference
  • references source dbo.QBM_ZDialogSemaphorIncGlobal source text reference
  • references source dbo.QBM_FTColumnsToWatch source text reference

Complete Source

SQL453 lines
1CREATE PROCEDURE QBM_PTriggerWatchCreate(2  @TableName varchar(30),3  @Operation varchar(16),4  @TriggerName varchar(30)5)6AS7BEGIN8  DECLARE @TriggerBody nvarchar(max) = ''9  DECLARE @SQLcmd nvarchar(max)10  DECLARE @SaveToQBMBufferConfig nvarchar(max) = ''11  DECLARE @VarDefinition nvarchar(max) = '	declare @XUser nvarchar(64) = object_name(@@procid)12	declare @Xdate datetime = getutcdate()'13  DECLARE @tabletype nvarchar(1)14  DECLARE @IsWatch BIT = 015  DECLARE @IsSemaphor BIT = 016  DECLARE @IsResidentTable BIT = 017  DECLARE @IsInsteadOf BIT = 018  DECLARE @IsXOriginHandling BIT = 019  DECLARE @IsXIsInEffectHandling BIT = 020  DECLARE @DebugLevel char(1) = 'W'21  DECLARE @DebugMessage nvarchar(4000)22  DECLARE @XDateSubItemUpdate nvarchar(max) = ''23  DECLARE @XMarkedForDeletionChg nvarchar(max) = ''24  DECLARE @SplittedLookup nvarchar(max) = ''25  DECLARE @CEF_SIEM nvarchar(max)26  DECLARE @DebugSwitch int = 027  DECLARE @IsTableRevision BIT = 028  DECLARE @TableRevision nvarchar(max)29  DECLARE @IsDeactivatedByPreProcessor BIT30  SET XACT_ABORT OFF31  BEGIN TRY32    SELECT33      TOP 1 @tabletype = t.TableType,34      @IsResidentTable = t.IsResident,35      @IsDeactivatedByPreProcessor = t.IsDeactivatedByPreProcessor36    FROM DialogTable t37      WITH(readpast)38    WHERE39      TableName = @TableName AND t.TableType NOT IN('M')40    IF @tabletype IN('R',41    'P',42    'U')43    BEGIN44      SELECT @IsInsteadOf = 145    END46    IF @Operation = 'UPDATE'47    BEGIN48      SELECT @SaveToQBMBufferConfig = dbo.QBM_FSQBufferConfigSaveOrigin(@TableName)49    END50    SELECT51      @TableRevision = dbo.QBM_FSQWatchRevision(@TableName,52      @Operation)53    IF @TableRevision > ' '54    BEGIN55      SELECT @IsTableRevision = 156    END57    IF @TableName IN(58      SELECT TableName59      FROM QBM_VHeavyLoadTables60      WHERE61        TableName <> 'DialogJournal')62    BEGIN63      GOTO ConfigBufferOnly64    END65    IF @TableName = 'DialogJournal'66    BEGIN67      GOTO CEFSIEMOnly68    END69    IF @IsDeactivatedByPreProcessor = 170    BEGIN71      GOTO dropOnly72    END73    IF EXISTS(74      SELECT TOP 1 175      FROM QBM_VSchemaColumns c76      WHERE77        c.TABLE_NAME = @TableName AND c.COLUMN_NAME = 'XOrigin') AND EXISTS(78    SELECT TOP 1 179    FROM QBM_VSchemaColumns c80    WHERE81      c.TABLE_NAME = @TableName AND c.COLUMN_NAME = 'XObjectKey')82    BEGIN83      SELECT @IsXOriginHandling = 184    END85    IF @IsXOriginHandling = 1 AND EXISTS(86      SELECT TOP 1 187      FROM QBM_VSchemaColumns c88      WHERE89        c.TABLE_NAME = @TableName AND c.COLUMN_NAME = 'XIsInEffect')90    BEGIN91      SELECT @IsXIsInEffectHandling = 192    END93    IF @tabletype = 'V'94    BEGIN95      GOTO DropOnly96    END97    IF NOT EXISTS(98      SELECT TOP 1 199      FROM information_schema.tables100      WHERE101        table_name = @TableName AND table_type IN('BASE TABLE', 'VIEW'))102    BEGIN103      GOTO DropOnly104    END105    IF '1' = dbo.QBM_FGIConfigparmValue('Common\ProcessState\PropertyLog')106    BEGIN107      IF @IsXOriginHandling = 1108      BEGIN109        IF @Operation = 'Update'110        BEGIN111          IF EXISTS(112            SELECT TOP 1 1113            FROM dbo.QBM_FTColumnsToWatch(@TableName, 'Delete')) OR EXISTS(114          SELECT TOP 1 1115          FROM dbo.QBM_FTColumnsToWatch(@TableName, 'Update'))116          BEGIN117            SELECT @IsWatch = 1118          END119        END120        IF @Operation = 'Insert'121        BEGIN122          IF EXISTS(123            SELECT TOP 1 1124            FROM dbo.QBM_FTColumnsToWatch(@TableName, 'Insert'))125          BEGIN126            SELECT @IsWatch = 1127          END128        END129      END130      ELSE131      BEGIN132        IF EXISTS(133          SELECT TOP 1 1134          FROM dbo.QBM_FTColumnsToWatch(@TableName, @Operation))135        BEGIN136          SELECT @IsWatch = 1137        END138      END139    END140    IF EXISTS(141      SELECT TOP 1 1142      FROM DialogTable t143      WITH(readpast)144    JOIN DialogColumn c145      WITH(readpast)146      ON c.UID_DialogTable = t.UID_DialogTable147    JOIN DialogColumnHasSemaphor chs148      WITH(readpast)149      ON c.UID_DialogColumn = chs.UID_DialogColumn150    WHERE151      t.TableName = @TableName AND(c.IsPKMember = 1 AND @Operation = 'insert' OR c.IsPKMember = 0 AND @Operation = 'update' OR c.IsPKMember =152    1 AND @Operation = 'delete'))153    BEGIN154      SELECT @IsSemaphor = 1155    END156    SELECT157      @XDateSubItemUpdate = dbo.QBM_FSQXDateSubItemUpdate(@TableName,158      @Operation)159    SELECT160      @XMarkedForDeletionChg = dbo.QBM_FSQXMarkedForDeletionChg(@TableName,161      @Operation)162    SELECT163      @SplittedLookup = dbo.QBM_FSQTriggerSplittedLookup(@TableName,164      @Operation)165    IF @IsWatch = 0 AND @IsInsteadOf = 0 AND @IsSemaphor = 0 AND @IsResidentTable = 0 AND @SaveToQBMBufferConfig = '' AND @IsXOriginHandling = 0 AND166    @XDateSubItemUpdate = '' AND @XMarkedForDeletionChg = '' AND @SplittedLookup = '' AND @IsTableRevision = 0167    BEGIN168      IF @DebugSwitch > 0169      BEGIN170        print 'drop only'171      END172      GOTO DropOnly173    END174    IF @IsWatch = 1 AND @Operation IN('UPDATE',175    'DELETE')176    BEGIN177      SELECT178        @VarDefinition = CONCAT(@Vardefinition,179        N '180 declare @DialogWatchProperty QBM_YWatchBufferProp181 declare @DialogWatchOperation QBM_YWatchBufferOp182183')184    END185    IF @XDateSubItemUpdate > ' '186    BEGIN187      SELECT188        @VarDefinition = CONCAT(@VarDefinition,189        '190	declare @UID_TaskXDateSubItemUpdate varchar(38) 191	declare @JustNowVarchar varchar(64) = dbo.QBM_FCVDatetimeToStringUTC(GetUTCDate())192	')193    END194    IF @IsXOriginHandling = 1 AND @Operation IN('UPDATE')195    BEGIN196      SELECT197        @VarDefinition = CONCAT(@VarDefinition,198        N '199	declare @EntriesToFire QBM_YParameterList 200	declare @AdditionalEntries QBM_YParameterList201	declare @StartAt datetime')202    END203    IF @IsSemaphor = 1 OR @XDateSubItemUpdate > ' ' OR @XMarkedForDeletionChg > ' '204    BEGIN205      SELECT206        @VarDefinition = CONCAT(@VarDefinition,207        N '208	declare @DBQueueElements QBM_YDBQueueRaw ')209    END210    IF @IsSemaphor = 1211    BEGIN212      SELECT213        @VarDefinition = CONCAT(@VarDefinition,214        N '215	declare @IsSemaphorInFullsync bit  = sign(len(dbo.QBM_FGISessionContext (''Fullsync'')))')216    END217    IF @tabletype IN('R',218    'P',219    'U')220    BEGIN221      SELECT222        @TriggerBody = CONCAT(N '	raiserror (N''#LDS#Operations on table {0} are not permitted.|',223        rtrim(@TableName),224        N '|'', 18, 1) with nowait')225    END226    ELSE227    BEGIN228      IF @IsSemaphor = 1229      BEGIN230        SELECT231          @Triggerbody = CONCAT(@Triggerbody,232          dbo.QBM_FSQTriggerWatchSemaphor(@TableName, @operation))233        IF @DebugSwitch > 0234        BEGIN235          SELECT236            @Debugmessage = CONCAT('semaphor für ',237            @TableName,238            nchar(9),239            @operation)240          EXEC QBM_PJournal @Debugmessage,241            @@PROCID,242          'D',243            @DebugLevel244        END245      END246      IF @IsResidentTable = 1247      BEGIN248        SELECT249          @Triggerbody = CONCAT(@Triggerbody,250          N '251		 exec QBM_ZDialogSemaphorIncGlobal 0, ''USERDATARESIDENT'', '''', @GenProcID252	 ')253      END254      IF @IsWatch = 1255      BEGIN256        SELECT257          @Triggerbody = CONCAT(@Triggerbody,258          dbo.QBM_FSQTriggerWatchTable(@TableName, @operation))259      END260    END261    IF @TableRevision > ' '262    BEGIN263      SELECT264        @TriggerBody = CONCAT(@TriggerBody,265        @TableRevision)266    END267    IF @XDateSubItemUpdate > ' '268    BEGIN269      SELECT270        @TriggerBody = CONCAT(@TriggerBody,271        @XDateSubItemUpdate)272    END273    IF @XMarkedForDeletionChg > ' '274    BEGIN275      SELECT276        @TriggerBody = CONCAT(@TriggerBody,277        @XMarkedForDeletionChg)278    END279    IF @IsXOriginHandling = 1 AND @Operation IN('UPDATE')280    BEGIN281      IF @DebugSwitch > 0282      BEGIN283        print '--------XOrigin-Anteil' print dbo.QBM_FSQTriggerWatchXOrigin(@TableName)284      END285      SELECT286        @TriggerBody = CONCAT(@TriggerBody,287        dbo.QBM_FSQTriggerWatchXOrigin(@TableName))288    END289    IF @IsXIsInEffectHandling = 1 AND @Operation IN('UPDATE')290    BEGIN291      IF @DebugSwitch > 0292      BEGIN293        print '--------XIsInEffect-Anteil' print dbo.QBM_FSQTriggerWatchXIsInEffect(@TableName)294      END295      SELECT296        @TriggerBody = CONCAT(@TriggerBody,297        dbo.QBM_FSQTriggerWatchXIsInEffect(@TableName))298    END299    IF @IsXOriginHandling = 1 AND @Operation IN('Delete')300    BEGIN301      SELECT302        @TriggerBody = CONCAT(@TriggerBody,303        N '304-- Handle Delete via XOrigin305 if exists (select top 1 1306			 from deleted307			 where XOrigin > 0308			)309	begin310		raiserror(''deleting Objects with XOrigin greater then 0 is not permitted'', 18, 1) with nowait311	end312		313-- / Handle Delete via XOrigin314315	'316        )317      IF @DebugSwitch > 0318      BEGIN319        print '## Delete error included'320      END321    END322    IF @SplittedLookup > ' '323    BEGIN324      SELECT325        @TriggerBody = CONCAT(@TriggerBody,326        @SplittedLookup)327    END328    CEFSIEMOnly:329    SELECT330      @CEF_SIEM = dbo.QBM_FSQTriggerPartCEF(@TableName,331      LEFT(@Operation, 1),332      0)333    IF @CEF_SIEM > ' '334    BEGIN335      SELECT336        @Triggerbody = CONCAT(@Triggerbody,337        @CEF_SIEM)338    END339    ConfigBufferOnly:340    SELECT341      @TriggerBody = CONCAT(@TriggerBody,342      @SaveToQBMBufferConfig)343    IF @triggerbody > ' '344    BEGIN345      SELECT346        @SQLcmd = dbo.QBM_FSQTriggerDef(@TriggerName,347        @TableName,348        @Operation,349        CONCAT(N '/* SET XACT_ABORT ON is implicit */ ', nchar(13), nchar(10), @TriggerBody),350        @VarDefinition,351        CONCAT('Trigger watch for ', @TableName, '(', @Operation, ')'))352      IF @DebugSwitch > 0353      BEGIN354        print substring(@SQLcmd,355        1,356        4000) print substring(@SQLcmd,357        4001,358        4000) print substring(@SQLcmd,359        8001,360        4000) print substring(@SQLcmd,361        12001,362        4000) print substring(@SQLcmd,363        16001,364        4000) print substring(@SQLcmd,365        20001,366        4000) print substring(@SQLcmd,367        24001,368        4000) print substring(@SQLcmd,369        28001,370        4000) print substring(@SQLcmd,371        32001,372        4000) print substring(@SQLcmd,373        36001,374        4000) print substring(@SQLcmd,375        40001,376        4000) print substring(@SQLcmd,377        44001,378        4000) print substring(@SQLcmd,379        48001,380        4000) print substring(@SQLcmd,381        52001,382        4000) print substring(@SQLcmd,383        56001,384        4000) print substring(@SQLcmd,385        60001,386        4000) print substring(@SQLcmd,387        64001,388        4000) print substring(@SQLcmd,389        68001,390        4000) print substring(@SQLcmd,391        72001,392        4000) print substring(@SQLcmd,393        76001,394        4000) print substring(@SQLcmd,395        80001,396        4000) print substring(@SQLcmd,397        84001,398        4000) print substring(@SQLcmd,399        88001,400        4000) print substring(@SQLcmd,401        92001,402        4000) print substring(@SQLcmd,403        96001,404        4000)405      END406      EXEC QBM_PSQLCreate @TriggerName,407      'T',408        @SQLcmd,409        @UnComment = 0410      IF @tabletype NOT IN('R',411      'P',412      'U') AND EXISTS(413      SELECT TOP 1 1414      FROM sys.objects o415      WHERE416        type = 'TR' AND o.name = @TriggerName)417      BEGIN418        SELECT419          @SQLcmd = CONCAT(N 'exec sp_settriggerorder ''',420          @Triggername,421          N ''', ''FIRST'', ''',422          @operation,423          N '''')424        EXEC QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQLcmd,425          @LockTimeout_ms = DEFAULT,426          @MaxWaitTimeForLock_s = 12.0,427          @ProcIDForJournal = DEFAULT,428          @HandleErrorSilent = 0,429          @ExecuteWithTransact = 0430      END431    END432    ELSE433    BEGIN434      EXEC QBM_PTriggerDrop @TriggerName435    END436  END TRY437  BEGIN CATCH438    EXEC QBM_PSessionErrorAdd DEFAULT439    IF @DebugSwitch > 0440    BEGIN441      EXEC QBM_PDebug 'SessionError',442        @@procid443    END444    DECLARE @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow()445    RAISERROR(@Rethrow,446    18,447    1)448      WITH NOWAIT449  END CATCH450  ende:451  RETURN dropOnly:452  EXEC QBM_PTriggerDrop @TriggerName453END
Open raw exported source
SQL · Raw89 lines
1                     create   procedure QBM_PTriggerWatchCreate (@TableName varchar(30),  @Operation varchar(16)  , @TriggerName varchar(30) ) as2 begin  declare @TriggerBody nvarchar(max) = '' declare @SQLcmd nvarchar(max) declare @SaveToQBMBufferConfig nvarchar(max) = '' declare @VarDefinition 3nvarchar(max) = '	declare @XUser nvarchar(64) = object_name(@@procid)4	declare @Xdate datetime = getutcdate()' declare @tabletype nvarchar(1)  declare5 @IsWatch bit = 0 declare @IsSemaphor bit = 0 declare @IsResidentTable bit = 0 declare @IsInsteadOf bit = 0  declare @IsXOriginHandling bit = 0  declare6 @IsXIsInEffectHandling bit = 0  declare @DebugLevel char(1) = 'W' declare @DebugMessage nvarchar(4000) declare @XDateSubItemUpdate nvarchar(max) = '' 7declare @XMarkedForDeletionChg nvarchar(max) = '' declare @SplittedLookup nvarchar(max) = '' declare @CEF_SIEM nvarchar(max) declare @DebugSwitch int =8 0 declare @IsTableRevision bit = 0 declare @TableRevision nvarchar(max) declare @IsDeactivatedByPreProcessor bit SET XACT_ABORT OFF BEGIN TRY select top9 1 @tabletype = t.TableType , @IsResidentTable = t.IsResident , @IsDeactivatedByPreProcessor = t.IsDeactivatedByPreProcessor from DialogTable t with (readpast10) where TableName = @TableName and t.TableType not in ('M')  if @tabletype in ('R', 'P', 'U') begin select @IsInsteadOf = 1 end if @Operation = 'UPDATE'11 begin select @SaveToQBMBufferConfig = dbo.QBM_FSQBufferConfigSaveOrigin(@TableName ) end select @TableRevision = dbo.QBM_FSQWatchRevision(@TableName ,12 @Operation) if @TableRevision > ' ' begin select @IsTableRevision = 1 end  if @TableName in (select TableName from QBM_VHeavyLoadTables where TableName13 <> 'DialogJournal'  ) begin goto ConfigBufferOnly end if @TableName = 'DialogJournal' begin goto CEFSIEMOnly end if @IsDeactivatedByPreProcessor = 1 begin14 goto dropOnly end if exists (select top 1 1 from QBM_VSchemaColumns c where c.TABLE_NAME = @TableName and c.COLUMN_NAME = 'XOrigin' ) and exists (select15 top 1 1 from QBM_VSchemaColumns c where c.TABLE_NAME = @TableName and c.COLUMN_NAME = 'XObjectKey' )  begin select @IsXOriginHandling = 1 end if @IsXOriginHandling16 = 1 and exists (select top 1 1 from QBM_VSchemaColumns c where c.TABLE_NAME = @TableName and c.COLUMN_NAME = 'XIsInEffect' ) begin select @IsXIsInEffectHandling17 = 1 end  if @tabletype = 'V' begin goto DropOnly end if not exists (select top 1 1 from information_schema.tables where table_name = @TableName and table_type18 in ('BASE TABLE', 'VIEW') ) begin  goto DropOnly end if '1' = dbo.QBM_FGIConfigparmValue('Common\ProcessState\PropertyLog') begin if @IsXOriginHandling19 = 1 begin if @Operation = 'Update' begin if exists (select top 1 1 from dbo.QBM_FTColumnsToWatch(@TableName , 'Delete') ) or exists (select top 1 1 from20 dbo.QBM_FTColumnsToWatch(@TableName , 'Update' ) ) begin select @IsWatch = 1 end end  if @Operation = 'Insert' begin if exists (select top 1 1 from dbo.QBM_FTColumnsToWatch21(@TableName , 'Insert') ) begin select @IsWatch = 1 end end  end else  begin if exists (select top 1 1 from dbo.QBM_FTColumnsToWatch(@TableName , @Operation22) ) begin select @IsWatch = 1 end end  end             if exists (select  top 1 1 from DialogTable t with (readpast) join DialogColumn c with (readpast23) on c.UID_DialogTable = t.UID_DialogTable join DialogColumnHasSemaphor chs with (readpast) on c.UID_DialogColumn = chs.UID_DialogColumn where t.TableName24 = @TableName and ( c.IsPKMember = 1 and @Operation = 'insert' or c.IsPKMember = 0 and @Operation = 'update' or c.IsPKMember = 1 and @Operation = 'delete'25 ) ) begin select @IsSemaphor = 1 end select @XDateSubItemUpdate = dbo.QBM_FSQXDateSubItemUpdate(@TableName, @Operation) select @XMarkedForDeletionChg 26= dbo.QBM_FSQXMarkedForDeletionChg(@TableName, @Operation) select @SplittedLookup = dbo.QBM_FSQTriggerSplittedLookup(@TableName, @Operation) if @IsWatch27 = 0 and @IsInsteadOf = 0 and @IsSemaphor = 0 and @IsResidentTable = 0 and @SaveToQBMBufferConfig = '' and @IsXOriginHandling = 0 and @XDateSubItemUpdate28 = '' and @XMarkedForDeletionChg = '' and @SplittedLookup = '' and @IsTableRevision = 0 begin  if @DebugSwitch > 0 begin print 'drop only' end goto DropOnly29 end if @IsWatch = 1 and @Operation in ('UPDATE', 'DELETE') begin select @VarDefinition = concat(@Vardefinition , N'30 declare @DialogWatchProperty QBM_YWatchBufferProp31 declare @DialogWatchOperation QBM_YWatchBufferOp3233'34) end if @XDateSubItemUpdate > ' ' begin select @VarDefinition = concat(@VarDefinition , '35	declare @UID_TaskXDateSubItemUpdate varchar(38) 36	declare @JustNowVarchar varchar(64) = dbo.QBM_FCVDatetimeToStringUTC(GetUTCDate())37	'38 ) end if @IsXOriginHandling = 1 and @Operation in ('UPDATE') begin select @VarDefinition = concat(@VarDefinition , N'39	declare @EntriesToFire QBM_YParameterList 40	declare @AdditionalEntries QBM_YParameterList41	declare @StartAt datetime'42 ) end if @IsSemaphor = 1 or @XDateSubItemUpdate > ' ' or @XMarkedForDeletionChg > ' ' begin select @VarDefinition = concat(@VarDefinition , N'43	declare @DBQueueElements QBM_YDBQueueRaw '44 ) end if @IsSemaphor = 1 begin select @VarDefinition = concat(@VarDefinition , N'45	declare @IsSemaphorInFullsync bit  = sign(len(dbo.QBM_FGISessionContext (''Fullsync'')))'46 ) end  if @tabletype in ('R', 'P', 'U') begin  select @TriggerBody = concat(N'	raiserror (N''#LDS#Operations on table {0} are not permitted.|' , rtrim47(@TableName ) , N'|'', 18, 1) with nowait') end else begin if @IsSemaphor = 1 begin select @Triggerbody = concat(@Triggerbody , dbo.QBM_FSQTriggerWatchSemaphor48 (@TableName , @operation)) if @DebugSwitch > 0 begin select @Debugmessage = concat('semaphor für ' , @TableName , nchar(9) , @operation) exec QBM_PJournal49 @Debugmessage, @@PROCID, 'D', @DebugLevel end  end if @IsResidentTable = 1 begin  select @Triggerbody = concat(@Triggerbody , N'50		 exec QBM_ZDialogSemaphorIncGlobal 0, ''USERDATARESIDENT'', '''', @GenProcID51	 '52 ) end if @IsWatch = 1 begin select @Triggerbody = concat(@Triggerbody , dbo.QBM_FSQTriggerWatchTable (@TableName , @operation)) end end if @TableRevision53 > ' ' begin select @TriggerBody = concat(@TriggerBody , @TableRevision) end if @XDateSubItemUpdate > ' ' begin select @TriggerBody = concat(@TriggerBody54 , @XDateSubItemUpdate) end if @XMarkedForDeletionChg > ' ' begin select @TriggerBody = concat(@TriggerBody , @XMarkedForDeletionChg) end if @IsXOriginHandling55 = 1 and @Operation in ('UPDATE') begin if @DebugSwitch > 0 begin print '--------XOrigin-Anteil' print dbo.QBM_FSQTriggerWatchXOrigin(@TableName) end select56 @TriggerBody = concat(@TriggerBody , dbo.QBM_FSQTriggerWatchXOrigin(@TableName)) end if @IsXIsInEffectHandling = 1 and @Operation in ('UPDATE') begin 57if @DebugSwitch > 0 begin print '--------XIsInEffect-Anteil' print dbo.QBM_FSQTriggerWatchXIsInEffect(@TableName) end select @TriggerBody = concat(@TriggerBody58 , dbo.QBM_FSQTriggerWatchXIsInEffect(@TableName)) end if @IsXOriginHandling = 1 and @Operation in ('Delete') begin select @TriggerBody = concat(@TriggerBody59 , N'60-- Handle Delete via XOrigin61 if exists (select top 1 162			 from deleted63			 where XOrigin > 064			)65	begin66		raiserror(''deleting Objects with XOrigin greater then 0 is not permitted'', 18, 1) with nowait67	end68		69-- / Handle Delete via XOrigin7071	'72 ) if @DebugSwitch > 0 begin print '## Delete error included' end end if @SplittedLookup > ' ' begin select @TriggerBody = concat(@TriggerBody , @SplittedLookup73) end  CEFSIEMOnly: select @CEF_SIEM = dbo.QBM_FSQTriggerPartCEF(@TableName, left(@Operation, 1), 0)  if @CEF_SIEM > ' ' begin select @Triggerbody = concat74(@Triggerbody , @CEF_SIEM) end  ConfigBufferOnly: select @TriggerBody = concat(@TriggerBody , @SaveToQBMBufferConfig) if @triggerbody > ' ' begin select75 @SQLcmd = dbo.QBM_FSQTriggerDef (@TriggerName , @TableName , @Operation , concat(N'/* SET XACT_ABORT ON is implicit */ ', nchar(13), nchar(10), @TriggerBody76 ) , @VarDefinition , concat('Trigger watch for ' , @TableName , '(' , @Operation , ')') ) if @DebugSwitch > 0 begin print substring(@SQLcmd, 1, 4000) 77print substring(@SQLcmd, 4001, 4000) print substring(@SQLcmd, 8001, 4000) print substring(@SQLcmd, 12001, 4000) print substring(@SQLcmd, 16001, 4000) print78 substring(@SQLcmd, 20001, 4000) print substring(@SQLcmd, 24001, 4000) print substring(@SQLcmd, 28001, 4000) print substring(@SQLcmd, 32001, 4000) print79 substring(@SQLcmd, 36001, 4000) print substring(@SQLcmd, 40001, 4000) print substring(@SQLcmd, 44001, 4000) print substring(@SQLcmd, 48001, 4000) print80 substring(@SQLcmd, 52001, 4000) print substring(@SQLcmd, 56001, 4000) print substring(@SQLcmd, 60001, 4000) print substring(@SQLcmd, 64001, 4000) print81 substring(@SQLcmd, 68001, 4000) print substring(@SQLcmd, 72001, 4000) print substring(@SQLcmd, 76001, 4000) print substring(@SQLcmd, 80001, 4000) print82 substring(@SQLcmd, 84001, 4000) print substring(@SQLcmd, 88001, 4000) print substring(@SQLcmd, 92001, 4000) print substring(@SQLcmd, 96001, 4000) end 83 exec QBM_PSQLCreate @TriggerName, 'T', @SQLcmd, @UnComment = 0 if @tabletype not in ('R', 'P', 'U') and exists (select top 1 1 from sys.objects o where84 type = 'TR' and o.name = @TriggerName ) begin select @SQLcmd = concat(N'exec sp_settriggerorder ''' , @Triggername , N''', ''FIRST'', ''' , @operation85 , N'''') exec QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQLcmd , @LockTimeout_ms = default , @MaxWaitTimeForLock_s = 12.0 , @ProcIDForJournal = default86 , @HandleErrorSilent = 0 , @ExecuteWithTransact = 0 end end else begin exec QBM_PTriggerDrop @TriggerName end END TRY BEGIN CATCH exec QBM_PSessionErrorAdd87 default if @DebugSwitch > 0 begin exec QBM_PDebug 'SessionError', @@procid end declare @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow() RAISERROR88 (@Rethrow, 18, 1) WITH NOWAIT END CATCH ende: return dropOnly: exec QBM_PTriggerDrop @TriggerName end 89