Back to OIM Explorer

dbo.QBM_PRITriggerCreate

Stored ProcedureSQL_STORED_PROCEDURESandbox DB

Stored Procedure.

Source: sandbox-db sys.sql_modules

Source size: 9.678 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_FGICodeName source text reference
  • references source dbo.QBM_FGIIsSimulationMode source text reference
  • references source dbo.QBM_FGIModuleExists source text reference
  • references source dbo.QBM_FGIPrimaryKeyCount source text reference
  • references source dbo.QBM_FGIPrimaryKeyName source text reference
  • references source dbo.QBM_FGIPrimaryKeyName_F source text reference
  • references source dbo.QBM_FGISessionErrorIsDeadlock source text reference
  • references source dbo.QBM_FGISessionErrorRethrow source text reference
  • references source dbo.QBM_FSQFKCheckDynamic source text reference
  • references source dbo.QBM_FSQFKCheckFix source text reference
  • references source dbo.QBM_FSQTriggerDef source text reference
  • references source dbo.QBM_PExecuteSQLWithRetry_LLP source text reference
  • references source dbo.QBM_PFESimulationFill source text reference
  • references source dbo.QBM_PJournal source text reference
  • references source dbo.QBM_PSessionErrorAdd source text reference
  • references source dbo.QBM_PSessionErrorClean source text reference
  • references source dbo.QBM_PTriggerDrop source text reference

Complete Source

SQL430 lines
1CREATE PROCEDURE QBM_PRITriggerCreate(2  @Table nvarchar(32),3  @Operation nvarchar(16)4)5AS6BEGIN7  DECLARE @TriggerName nvarchar(64)8  DECLARE @TrigggerOpPrefix nvarchar(1)9  DECLARE @TriggerBody nvarchar(max) = N ''10  DECLARE @SQLcmd nvarchar(max)11  DECLARE @PkUpdateRestrict nvarchar(max)12  DECLARE @PKUpdateJoin nvarchar(max)13  DECLARE @PKName1 varchar(30)14  DECLARE @PKName2 varchar(30)15  DECLARE @PKCount int16  DECLARE @VarDefinition nvarchar(max)17  DECLARE @UID_QBMRelation varchar(38)18  DECLARE @Fragment nvarchar(16)19  DECLARE @uid_Dialogtable varchar(38)20  DECLARE @DebugLevel char(1) = 'W'21  DECLARE @erg int = 022  DECLARE @DebugSwitch int = 023  DECLARE @Relations QBM_YCursorBuffer24  SET XACT_ABORT OFF25  BEGIN TRY26    SELECT @TrigggerOpPrefix = CASE @Operation27    WHEN 'Insert' THEN28    '1'29    WHEN 'update' THEN30    '2'31    WHEN 'delete' THEN32    '3'33    END34    SELECT TOP 1 @uid_Dialogtable = uid_dialogtable35    FROM DialogTable36      WITH(readpast)37    WHERE38      TableName = @Table39    SELECT40      @TriggerName = dbo.QBM_FGICodeName('T' + @TrigggerOpPrefix,41      rtrim(@Table))42    IF @Table IN(43      SELECT TableName44      FROM QBM_VHeavyLoadTables)45    BEGIN46      GOTO ende47    END48    IF NOT EXISTS(49      SELECT TOP 1 150      FROM sys.tables t51      WHERE52        t.name = @Table)53    BEGIN54      GOTO ende55    END56    SELECT57      @VarDefinition = N '58	declare @IsSimulationMode bit = dbo.QBM_FGIIsSimulationMode() 59	declare @DBQueueElements QBM_YDBQueueRaw60	declare @XUser nvarchar(64) = object_name(@@procid)61	declare @Xdate datetime = getutcdate()62	declare @SimulationModeBuffer QBM_YTriggerOperation63	declare @InvalidValue varchar(138)64	declare @InvalidMessage nvarchar(max)65	'66    IF @operation = 'Delete' AND EXISTS(67      SELECT TOP 1 168      FROM QBMRelation r69      WITH(readpast)70    JOIN DialogColumn c71      WITH(readpast)72      ON r.UID_ChildColumn = c.UID_DialogColumn73    WHERE74      c.UID_DialogTable = @uid_Dialogtable AND(GenerateParent = 'TDX'))75    BEGIN76      SELECT77        @VarDefinition = @VarDefinition + nchar(13) + nchar(10) + N '  declare @ElementsLater QBM_YParameterList ' + nchar(13) + nchar(10) + N78        '  declare @WorkWhere nvarchar(max)' + nchar(13) + nchar(10)79    END80    IF @operation = 'update'81    BEGIN82      SELECT @PKUpdateRestrict = N ''83      SELECT @PKUpdateJoin = N ''84      SELECT @PKCount = dbo.QBM_FGIPrimaryKeyCount(@Table)85      IF NOT EXISTS(86        SELECT TOP 1 187        FROM DialogTable t88        WHERE89          t.UID_DialogTable = @uid_Dialogtable AND t.isMNTable = 1 AND t.usagetype NOT IN('WORK')) AND @PKCount > 090      BEGIN91        SELECT92          @PKName1 = dbo.QBM_FGIPrimaryKeyName_F(@table,93          1)94        SELECT95          @PKName2 = dbo.QBM_FGIPrimaryKeyName_F(@table,96          2)97        SELECT @PKUpdateRestrict = N 'update(' + @PKName1 + ')'98        SELECT @PKUpdateJoin = N 'deleted.' + @PKName1 + N ' = inserted.' + @PKName199        IF @PKCount = 2100        BEGIN101          SELECT @PKUpdateRestrict = @PKUpdateRestrict + N '102			 or update(' + @PKName2 + ')'103          SELECT104            @PKUpdateJoin = @PKUpdateJoin + N '105			 and deleted.' + @PKName2 + N ' = inserted.' + @PKName2106        END107      END108      IF @PKUpdateRestrict > ' '109      BEGIN110        SELECT111          @TriggerBody = @TriggerBody + N '112 if ' + @PKUpdateRestrict + N '113  begin114	if (select count(*) from deleted, inserted115		where ' + @PKUpdateJoin116          + N '117		)  <> (select count(*) from inserted)118	 begin119			RAISERROR(''#LDS#Not allowed to change the primary key in table {0}.|' + @Table + N '|'', 18, 2) WITH NOWAIT120	 end121  end122123'124      END125    END126    IF @operation = 'Update' AND EXISTS(127      SELECT TOP 1 1128      FROM QBMRelation r129      WITH(readpast)130    JOIN DialogColumn c131      WITH(readpast)132      ON r.UID_ChildColumn = c.UID_DialogColumn133    WHERE134      c.UID_DialogTable = @uid_Dialogtable AND(GenerateParent = 'TDS' OR GenerateChild = 'CDS')) AND EXISTS(135    SELECT TOP 1 1136    FROM dialogColumn c137      WITH(readpast)138    WHERE139      c.UID_DialogTable = @uid_Dialogtable AND Columnname = 'XObjectKey')140    BEGIN141      SELECT142        @TriggerBody = @TriggerBody + N '  -- select @ I s S i m u l a t i o n M o d e   =   d b o . Q B M _ F G I I s S i m u l a t i o n M o d e ()  -- ist jetzt schon im declare143	if @IsSimulationMode = 1144	  begin145146		delete @SimulationModeBuffer147'148      DELETE @Relations149      INSERT INTO @Relations(UID1,150      Ident1)151      SELECT152        r.UID_QBMRelation,153        'DS'154      FROM QBMRelation r155        WITH(readpast)156      JOIN DialogColumn c157        WITH(readpast)158        ON r.UID_ChildColumn = c.UID_DialogColumn159      WHERE160        c.UID_DialogTable = @uid_Dialogtable AND(GenerateParent = 'TDS' OR GenerateChild = 'CDS')161      ORDER BY 1162      SELECT @UID_QBMRelation = '#'163      WHILE @UID_QBMRelation > ' '164      BEGIN165        SELECT @UID_QBMRelation = NULL166        SELECT167          TOP 1 @UID_QBMRelation = r.UID1,168          @fragment = r.Ident1169        FROM @Relations r170        ORDER BY r.Int1171        IF @UID_QBMRelation IS NULL172        BEGIN173          CONTINUE174        END175        DELETE @Relations176        WHERE177          UID1 = @UID_QBMRelation178        SELECT179          @TriggerBody = @TriggerBody + dbo.QBM_FSQFKCheckFix(@UID_QBMRelation,180          'DS',181          @Operation)182        EXEC QBM_PJournal @sqlcmd,183          @@PROCID,184        'D',185          @DebugLevel186      END187      SELECT188        @TriggerBody = @TriggerBody + N '189		exec QBM_PFESimulationFill @SimulationModeBuffer190191	  end /* if @IsSimulationMode = 1 */ 192'193    END194    IF @operation = 'Delete' AND EXISTS(195      SELECT TOP 1 1196      FROM QBMRelation r197      WITH(readpast)198    JOIN DialogColumn c199      WITH(readpast)200      ON r.UID_ChildColumn = c.UID_DialogColumn201    WHERE202      c.UID_DialogTable = @uid_Dialogtable AND(GenerateParent IN('TDC', 'TDX') OR GenerateChild = 'CDC')) AND EXISTS(203    SELECT TOP 1 1204    FROM dialogColumn c205      WITH(readpast)206    WHERE207      c.UID_DialogTable = @uid_Dialogtable AND Columnname = 'XObjectKey')208    BEGIN209      SELECT210        @TriggerBody = @TriggerBody + N '  -- select @ I s S i m u l a t i o n M o d e   =   d b o . Q B M _ F G I I s S i m u l a t i o n M o d e()  -- ist jetzt schon im declare211	if @IsSimulationMode = 1212	 begin213		delete @SimulationModeBuffer214215		insert into @SimulationModeBuffer (operation, BaseObjectType, ColumnName, Objectkey, OldValue) 216						select ''D'', '''217        + @Table + N ''', '''', deleted.XObjectKey , N''''218						 from deleted219220		exec QBM_PFESimulationFill @SimulationModeBuffer221222	 end 223'224    END225    IF @operation IN('Insert',226    'Update')227    BEGIN228      DELETE @Relations229      INSERT INTO @Relations(Ident1,230      UID1)231      SELECT CASE r.GenerateChild232      WHEN 'TIR' THEN233      CASE @Operation234        WHEN 'insert' THEN235      'TII'236      ELSE 'TIR'237      END238      ELSE r.generateChild239      END AS fragment,240      r.UID_QBMRelation241      FROM QBMRelation r242        WITH(readpast)243      JOIN DialogColumn c244        WITH(readpast)245        ON r.UID_ChildColumn = c.UID_DialogColumn246      WHERE247        c.UID_DialogTable = @uid_Dialogtable AND r.GenerateChild > ' ' AND r.GenerateChild LIKE 'T%'248      ORDER BY r.UID_QBMRelation249      SELECT @UID_QBMRelation = '#'250      WHILE @UID_QBMRelation > ' '251      BEGIN252        SELECT @UID_QBMRelation = NULL253        SELECT254          TOP 1 @UID_QBMRelation = r.UID1,255          @fragment = r.Ident1256        FROM @Relations r257        ORDER BY r.Int1258        IF @UID_QBMRelation IS NULL259        BEGIN260          CONTINUE261        END262        DELETE @Relations263        WHERE264          UID1 = @UID_QBMRelation265        SELECT266          @TriggerBody = @Triggerbody + dbo.QBM_FSQFKCheckFix(@UID_QBMRelation,267          @Fragment,268          @Operation)269      END270    END271    IF @operation IN('Delete')272    BEGIN273      DELETE @Relations274      INSERT INTO @Relations(Ident1,275      UID1)276      SELECT277        r.Generateparent,278        r.UID_QBMRelation279      FROM QBMRelation r280        WITH(readpast)281      JOIN DialogColumn p282        WITH(readpast)283        ON r.UID_ParentColumn = p.UID_DialogColumn284      JOIN QBMModuleDef m285        ON286      LEFT(r.UID_QBMRelation,287      3) = m.ModuleName288      WHERE289        p.UID_DialogTable = @uid_Dialogtable AND r.Generateparent > ' ' AND r.Generateparent LIKE 'T%'290      ORDER BY m.Sortorder,291      r.UID_QBMRelation292      SELECT @UID_QBMRelation = '#'293      WHILE @UID_QBMRelation > ' '294      BEGIN295        SELECT @UID_QBMRelation = NULL296        SELECT297          TOP 1 @UID_QBMRelation = r.UID1,298          @fragment = r.Ident1299        FROM @Relations r300        ORDER BY r.ElementIndex301        IF @UID_QBMRelation IS NULL302        BEGIN303          CONTINUE304        END305        DELETE @Relations306        WHERE307          UID1 = @UID_QBMRelation308        SELECT309          @TriggerBody = @Triggerbody + dbo.QBM_FSQFKCheckFix(@UID_QBMRelation,310          @Fragment,311          @Operation)312      END313    END314    SELECT315      @TriggerBody = @TriggerBody + dbo.QBM_FSQFKCheckDynamic(@Table,316      @Operation)317    IF dbo.QBM_FGIModuleExists('QER') = 1318    BEGIN319      SELECT320        @TriggerBody = REPLACE(@TriggerBody,321        '%ModQER%',322        '')323    END324    ELSE325    BEGIN326      SELECT327        @TriggerBody = REPLACE(@TriggerBody,328        '%ModQER%',329        '--')330    END331    SELECT332      @SQLcmd = dbo.QBM_FSQTriggerDef(@TriggerName,333      @Table,334      @Operation,335      @TriggerBody,336      @VarDefinition,337      'Trigger referential integrity for ' + @Table + '(' + @Operation + ')')338    IF len(@triggerbody) > 0 AND @operation IN('insert',339    'update',340    'delete')341    BEGIN342      EXEC QBM_PJournal @sqlcmd,343        @@PROCID,344      'D',345        @DebugLevel346      IF @DebugSwitch > 0347      BEGIN348        print @SQLcmd print substring(@SQLcmd,349        4000,350        4000) print substring(@SQLcmd,351        8000,352        4000) print substring(@SQLcmd,353        12000,354        4000) print substring(@SQLcmd,355        16000,356        4000)357      END358      BEGIN TRY359        EXEC QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQLcmd,360          @LockTimeout_ms = DEFAULT,361          @MaxWaitTimeForLock_s = 10,362          @ProcIDForJournal = DEFAULT,363          @HandleErrorSilent = 0,364          @ExecuteWithTransact = 0365        EXEC QBM_PSessionErrorClean366      END TRY367      BEGIN CATCH368        EXEC QBM_PSessionErrorAdd DEFAULT,369          @SQLcmd370        IF dbo.QBM_FGISessionErrorIsDeadlock(DEFAULT) = 1371        BEGIN372          SELECT @erg = 1373        END374        ELSE375        BEGIN376          SELECT @erg = -1377        END378      END CATCH379      IF @erg <> 0380      BEGIN381        GOTO FehlerCodeAuswerten382      END383      SELECT384        @SQLcmd = N 'exec sp_settriggerorder ''' + @Triggername + N ''', ''LAST'', ''' + @operation + N ''''385      BEGIN TRY386        EXEC QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQLcmd,387          @LockTimeout_ms = DEFAULT,388          @MaxWaitTimeForLock_s = DEFAULT,389          @ProcIDForJournal = DEFAULT,390          @HandleErrorSilent = 0,391          @ExecuteWithTransact = 0392        EXEC QBM_PSessionErrorClean393      END TRY394      BEGIN CATCH395        EXEC QBM_PSessionErrorAdd DEFAULT,396          @SQLcmd397        IF dbo.QBM_FGISessionErrorIsDeadlock(DEFAULT) = 1398        BEGIN399          SELECT @erg = 1400        END401        ELSE402        BEGIN403          SELECT @erg = -1404        END405      END CATCH406      FehlerCodeAuswerten:407      IF @erg < 0408      BEGIN409        RAISERROR('',410        18,411        1)412          WITH nowait413      END414    END415    ELSE416    BEGIN417      EXEC QBM_PTriggerDrop @TriggerName418    END419  END TRY420  BEGIN CATCH421    EXEC QBM_PSessionErrorAdd DEFAULT422    DECLARE @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow()423    RAISERROR(@Rethrow,424    18,425    1)426      WITH NOWAIT427  END CATCH428  ende:429  RETURN(@erg)430END
Open raw exported source
SQL ยท Raw99 lines
1            create   procedure QBM_PRITriggerCreate (@Table nvarchar(32),  @Operation nvarchar(16)  ) as begin  declare @TriggerName nvarchar(642) declare @TrigggerOpPrefix nvarchar(1) declare @TriggerBody nvarchar(max) = N'' declare @SQLcmd nvarchar(max) declare @PkUpdateRestrict nvarchar(max) 3declare @PKUpdateJoin nvarchar(max) declare @PKName1 varchar(30) declare @PKName2 varchar(30) declare @PKCount int declare @VarDefinition nvarchar(max)4 declare @UID_QBMRelation varchar(38) declare @Fragment nvarchar(16) declare @uid_Dialogtable varchar(38) declare @DebugLevel char(1) = 'W' declare @erg5 int = 0 declare @DebugSwitch int = 0  declare @Relations QBM_YCursorBuffer    SET XACT_ABORT OFF BEGIN TRY select @TrigggerOpPrefix = case @Operation 6when 'Insert' then '1' when 'update' then '2' when 'delete' then '3' end select top 1 @uid_Dialogtable = uid_dialogtable from DialogTable with (readpast7) where TableName = @Table select @TriggerName = dbo.QBM_FGICodeName( 'T' + @TrigggerOpPrefix, rtrim(@Table))   if @Table in (select TableName from QBM_VHeavyLoadTables8  ) begin goto ende end  if not exists (select top 1 1 from sys.tables t where t.name = @Table ) begin  goto ende end select @VarDefinition = N'9	declare @IsSimulationMode bit = dbo.QBM_FGIIsSimulationMode() 10	declare @DBQueueElements QBM_YDBQueueRaw11	declare @XUser nvarchar(64) = object_name(@@procid)12	declare @Xdate datetime = getutcdate()13	declare @SimulationModeBuffer QBM_YTriggerOperation14	declare @InvalidValue varchar(138)15	declare @InvalidMessage nvarchar(max)16	'17   if @operation = 'Delete' and exists (select top 1 1 from QBMRelation r with (readpast) join DialogColumn c with (readpast) on r.UID_ChildColumn = c.UID_DialogColumn18 where c.UID_DialogTable = @uid_Dialogtable and ( GenerateParent = 'TDX' ) ) begin select @VarDefinition = @VarDefinition + nchar(13) + nchar(10) + N'  declare @ElementsLater QBM_YParameterList '19 + nchar(13) + nchar(10) + N'  declare @WorkWhere nvarchar(max)' + nchar(13) + nchar(10) end  if @operation = 'update' begin select @PKUpdateRestrict =20 N'' select @PKUpdateJoin = N'' select @PKCount = dbo.QBM_FGIPrimaryKeyCount(@Table)  if not exists (select top 1 1 from DialogTable t where t.UID_DialogTable21 = @uid_Dialogtable and t.isMNTable = 1   and t.usagetype not in ('WORK') ) and @PKCount > 0 begin select @PKName1 = dbo.QBM_FGIPrimaryKeyName_F(@table22, 1) select @PKName2 = dbo.QBM_FGIPrimaryKeyName_F(@table, 2) select @PKUpdateRestrict = N'update(' + @PKName1 + ')' select @PKUpdateJoin = N'deleted.'23 + @PKName1 + N' = inserted.' + @PKName1 if @PKCount = 2 begin select @PKUpdateRestrict = @PKUpdateRestrict + N'24			 or update(' + @PKName2 + ')' select25 @PKUpdateJoin = @PKUpdateJoin + N'26			 and deleted.' + @PKName2 + N' = inserted.' + @PKName2 end end  if @PKUpdateRestrict > ' ' begin select @TriggerBody27 = @TriggerBody + N'28 if ' + @PKUpdateRestrict + N'29  begin30	if (select count(*) from deleted, inserted31		where ' + @PKUpdateJoin + N'32		)  <> (select count(*) from inserted)33	 begin34			RAISERROR(''#LDS#Not allowed to change the primary key in table {0}.|'35 + @Table + N'|'', 18, 2) WITH NOWAIT36	 end37  end3839' end  end    if @operation = 'Update' and exists (select top 1 1 from QBMRelation r with (readpast40) join DialogColumn c with (readpast) on r.UID_ChildColumn = c.UID_DialogColumn where c.UID_DialogTable = @uid_Dialogtable and ( GenerateParent = 'TDS'41 or GenerateChild = 'CDS' ) )  and exists (select top 1 1 from dialogColumn c with (readpast) where c.UID_DialogTable = @uid_Dialogtable and Columnname42 = 'XObjectKey' )  begin select @TriggerBody = @TriggerBody + N'  -- select @ I s S i m u l a t i o n M o d e   =   d b o . Q B M _ F G I I s S i m u l a t i o n M o d e ()  -- ist jetzt schon im declare43	if @IsSimulationMode = 144	  begin4546		delete @SimulationModeBuffer47'48 delete  @Relations  insert into @Relations (UID1  , Ident1 ) select r.UID_QBMRelation, 'DS' from QBMRelation r with (readpast) join DialogColumn c with49 (readpast) on r.UID_ChildColumn = c.UID_DialogColumn where c.UID_DialogTable = @uid_Dialogtable and ( GenerateParent = 'TDS' or GenerateChild = 'CDS' 50)  order by 1  select @UID_QBMRelation = '#' while @UID_QBMRelation > ' ' begin select @UID_QBMRelation = null select top 1 @UID_QBMRelation = r.UID1  51, @fragment = r.Ident1  from @Relations r order by r.Int1  if @UID_QBMRelation is null begin continue end delete  @Relations where UID1  = @UID_QBMRelation52 select @TriggerBody = @TriggerBody + dbo.QBM_FSQFKCheckFix (@UID_QBMRelation, 'DS' , @Operation) exec QBM_PJournal @sqlcmd, @@PROCID, 'D', @DebugLevel53 end  select @TriggerBody = @TriggerBody + N'54		exec QBM_PFESimulationFill @SimulationModeBuffer5556	  end /* if @IsSimulationMode = 1 */ 57' end   if58 @operation = 'Delete' and exists (select top 1 1 from QBMRelation r with (readpast) join DialogColumn c with (readpast) on r.UID_ChildColumn = c.UID_DialogColumn59 where c.UID_DialogTable = @uid_Dialogtable and ( GenerateParent in( 'TDC', 'TDX') or GenerateChild = 'CDC' ) )  and exists (select top 1 1 from dialogColumn60 c with (readpast) where c.UID_DialogTable = @uid_Dialogtable and Columnname = 'XObjectKey' )  begin select @TriggerBody = @TriggerBody + N'  -- select @ I s S i m u l a t i o n M o d e   =   d b o . Q B M _ F G I I s S i m u l a t i o n M o d e()  -- ist jetzt schon im declare61	if @IsSimulationMode = 162	 begin63		delete @SimulationModeBuffer6465		insert into @SimulationModeBuffer (operation, BaseObjectType, ColumnName, Objectkey, OldValue) 66						select ''D'', '''67 + @Table + N''', '''', deleted.XObjectKey , N''''68						 from deleted6970		exec QBM_PFESimulationFill @SimulationModeBuffer7172	 end 73' end    if @operation74 in ( 'Insert', 'Update') begin delete  @Relations  insert into @Relations (Ident1 , UID1 ) select  case r.GenerateChild when 'TIR' then case @Operation75 when 'insert' then 'TII' else 'TIR' end else r.generateChild end as fragment , r.UID_QBMRelation from QBMRelation r with (readpast) join DialogColumn 76c with (readpast) on r.UID_ChildColumn = c.UID_DialogColumn where c.UID_DialogTable = @uid_Dialogtable and r.GenerateChild > ' ' and r.GenerateChild like77 'T%'  order by r.UID_QBMRelation  select @UID_QBMRelation = '#' while @UID_QBMRelation > ' ' begin select @UID_QBMRelation = null select top 1 @UID_QBMRelation78 = r.UID1  , @fragment = r.Ident1  from @Relations r order by r.Int1  if @UID_QBMRelation is null begin continue end delete  @Relations  where UID1  = 79@UID_QBMRelation  select @TriggerBody = @Triggerbody + dbo.QBM_FSQFKCheckFix (@UID_QBMRelation, @Fragment, @Operation) end  end  if @operation in ( 'Delete'80) begin delete  @Relations  insert into @Relations (Ident1 , UID1 ) select r.Generateparent, r.UID_QBMRelation from QBMRelation r with (readpast) join 81DialogColumn p with (readpast) on r.UID_ParentColumn = p.UID_DialogColumn  join QBMModuleDef m on left(r.UID_QBMRelation, 3) = m.ModuleName where p.UID_DialogTable82 = @uid_Dialogtable and r.Generateparent > ' ' and r.Generateparent like 'T%'  order by m.Sortorder, r.UID_QBMRelation  select @UID_QBMRelation = '#' while83 @UID_QBMRelation > ' ' begin select @UID_QBMRelation = null select top 1 @UID_QBMRelation = r.UID1  , @fragment = r.Ident1  from @Relations r order by84 r.ElementIndex  if @UID_QBMRelation is null begin continue end delete  @Relations  where UID1  = @UID_QBMRelation select @TriggerBody = @Triggerbody +85 dbo.QBM_FSQFKCheckFix (@UID_QBMRelation, @Fragment, @Operation) end  end  select @TriggerBody = @TriggerBody + dbo.QBM_FSQFKCheckDynamic(@Table, @Operation86)   if dbo.QBM_FGIModuleExists('QER') = 1 begin select @TriggerBody = REPLACE(@TriggerBody, '%ModQER%', '') end else begin select @TriggerBody = REPLACE87(@TriggerBody, '%ModQER%', '--') end  select @SQLcmd = dbo.QBM_FSQTriggerDef (@TriggerName , @Table , @Operation , @TriggerBody , @VarDefinition , 'Trigger referential integrity for '88 + @Table + '(' + @Operation + ')' )      if len(@triggerbody) > 0 and @operation in ('insert', 'update', 'delete') begin exec QBM_PJournal @sqlcmd, @@PROCID89, 'D', @DebugLevel if @DebugSwitch > 0 begin print @SQLcmd print substring(@SQLcmd, 4000, 4000) print substring(@SQLcmd, 8000, 4000) print substring(@SQLcmd90, 12000, 4000) print substring(@SQLcmd, 16000, 4000) end BEGIN TRY exec QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQLcmd , @LockTimeout_ms = default91 , @MaxWaitTimeForLock_s = 10 , @ProcIDForJournal = default , @HandleErrorSilent = 0  , @ExecuteWithTransact = 0 exec QBM_PSessionErrorClean END TRY BEGIN92 CATCH exec QBM_PSessionErrorAdd default, @SQLcmd if dbo.QBM_FGISessionErrorIsDeadlock(default) = 1 begin select @erg = 1 end else begin select @erg = 93-1 end END CATCH if @erg <> 0 begin goto FehlerCodeAuswerten end select @SQLcmd = N'exec sp_settriggerorder ''' + @Triggername + N''', ''LAST'', ''' + 94@operation + N'''' BEGIN TRY exec QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQLcmd , @LockTimeout_ms = default , @MaxWaitTimeForLock_s = default , 95@ProcIDForJournal = default , @HandleErrorSilent = 0  , @ExecuteWithTransact = 0 exec QBM_PSessionErrorClean END TRY BEGIN CATCH exec QBM_PSessionErrorAdd96 default, @SQLcmd if dbo.QBM_FGISessionErrorIsDeadlock(default) = 1 begin select @erg = 1 end else begin select @erg = -1 end END CATCH FehlerCodeAuswerten:97  if @erg < 0 begin raiserror ('', 18, 1) with nowait end   end else begin  exec QBM_PTriggerDrop @TriggerName end END TRY BEGIN CATCH exec QBM_PSessionErrorAdd98 default declare @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow() RAISERROR (@Rethrow, 18, 1) WITH NOWAIT END CATCH ende: return (@erg) end 99