dbo.QBM_PConstraintEnable
Stored ProcedureSQL_STORED_PROCEDURESandbox DB
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_FGISessionErrorIsDeadlock source text reference
- references source dbo.QBM_FGISessionErrorRethrow source text reference
- references source dbo.QBM_PExecuteSQLWithRetry_LLP source text reference
- references source dbo.QBM_PIndicatorChange source text reference
- references source dbo.QBM_PJournal source text reference
- references source dbo.QBM_PSessionErrorAdd source text reference
Complete Source
1CREATE PROCEDURE QBM_PConstraintEnable(2 @TableName nvarchar(64) = N '%',3 @HandleErrorSilent BIT = 0,4 @force BIT = 05)6AS7BEGIN8 DECLARE @TabAktuell nvarchar(64)9 DECLARE @elements QBM_YCursorBuffer10 DECLARE @ElementCount int11 DECLARE @ElementIndex int12 DECLARE @JournalMessage nvarchar(1000)13 DECLARE @DebugLevel varchar(1) = 'I'14 DECLARE @MessageType varchar(1) = 'I'15 DECLARE @ErrorMessage nvarchar(4000)16 DECLARE @ErrorSeverity int17 DECLARE @ErrorState int18 DECLARE @WarFehlerhaft int = 019 DECLARE @CountElementsChanged int = 020 DECLARE @ErrorBuffer QBM_YSessionError21 DECLARE @SQL nvarchar(max)22 SET XACT_ABORT OFF23 BEGIN TRY24 IF EXISTS(25 SELECT TOP 1 126 FROM DialogDatabase d27 WHERE28 d.UpdatePhase NOT IN(0)) AND @force = 029 BEGIN30 GOTO endLabel31 END32 INSERT INTO @elements(Ident2)33 SELECT34 DISTINCT c.name AS TableName35 FROM sys.foreign_keys fk36 JOIN sys.objects c37 ON c.object_id = fk.parent_object_id38 JOIN sys.objects p39 ON p.object_id = fk.referenced_object_id40 WHERE41 fk.type = 'F' AND(c.name LIKE @TableName) AND(convert(int, fk.is_disabled)) = 142 SELECT @ElementCount = @@ROWCOUNT43 SELECT @ElementIndex = 144 WHILE @ElementIndex <= @ElementCount AND @WarFehlerhaft = 045 BEGIN46 SELECT TOP 1 @TabAktuell = bu.Ident247 FROM @elements bu48 WHERE49 bu.ElementIndex = @ElementIndex50 BEGIN TRY51 SELECT52 @SQL = CONCAT('53 alter Table ',54 @TabAktuell,55 ' with nocheck check constraint all ')56 EXEC QBM_PExecuteSQLWithRetry_LLP @SQLStatement = @SQL,57 @LockTimeout_ms = 2500,58 @MaxWaitTimeForLock_s = 10,59 @ProcIDForJournal = DEFAULT,60 @HandleErrorSilent = 0,61 @ExecuteWithTransact = 062 SELECT @CountElementsChanged += 163 END TRY64 BEGIN CATCH65 IF @HandleErrorSilent = 066 BEGIN67 EXEC QBM_PSessionErrorAdd DEFAULT68 IF dbo.QBM_FGISessionErrorIsDeadlock(DEFAULT) = 069 BEGIN70 INSERT INTO @ErrorBuffer(ErrorMessage,71 ErrorSeverity,72 ErrorState,73 ErrorNumber,74 ProcedureName,75 ProcedureLine,76 MessageDate,77 GenProcID,78 RepeatCounter,79 IsReThrow,80 SourceCode)81 SELECT82 '#LDS#Possible invalid foreign keys, run consistency checks: {0}|',83 ERROR_SEVERITY(),84 ERROR_STATE(),85 50000,86 ERROR_PROCEDURE(),87 ERROR_LINE(),88 GETUTCDATE(),89 NULL,90 0,91 0,92 NULL93 EXEC QBM_PSessionErrorAdd @ErrorBuffer94 EXEC QBM_PJournal 'SessionError',95 @@procid,96 'E',97 @DebugLevel,98 2099 END100 END101 SELECT @WarFehlerhaft = 1102 END CATCH103 SELECT @ElementIndex += 1104 END105 IF @CountElementsChanged > 0 AND EXISTS(106 SELECT TOP 1 1107 FROM sys.objects o108 WHERE109 o.name = 'QBM_PJournal' AND type = 'P')110 BEGIN111 SELECT112 @JournalMessage = '#LDS#System elements modified by {0}, pattern {1}, elements affected {2}.|' + isnull(OBJECT_NAME(@@procid),113 '') + '|' + @TableName + '|' + dbo.QBM_FCVIntToString(@CountElementsChanged) + '|'114 IF NOT EXISTS(115 SELECT TOP 1 1116 FROM DialogDatabase117 WHERE118 IsMainDatabase = 1 AND UpdatePhase <> 0) AND NOT EXISTS(119 SELECT TOP 1 1120 FROM sys.tables t121 WITH(readpast)122 JOIN sys.columns c123 WITH(readpast)124 ON t.object_id = c.object_id125 WHERE126 t.name = 'DialogDatabase' AND c.name = 'InitialMigrationRunning')127 BEGIN128 EXEC QBM_PJournal @JournalMessage,129 @@procid,130 @MessageType,131 @DebugLevel,132 20133 END134 ELSE135 BEGIN136 EXEC QBM_PJournal @JournalMessage,137 @@procid,138 'I',139 'I'140 END141 END142 EXEC QBM_PIndicatorChange 1143 END TRY144 BEGIN CATCH145 EXEC QBM_PSessionErrorAdd DEFAULT146 DECLARE @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow()147 RAISERROR(@Rethrow,148 18,149 1)150 WITH NOWAIT151 END CATCH152 endLabel:153 RETURN(@WarFehlerhaft)154END
Open raw exported source
1 create procedure QBM_PConstraintEnable (@TableName nvarchar(64)= N'%' ,@HandleErrorSilent bit = 0 , @force bit = 0 ) as begin declare @TabAktuell2 nvarchar(64) declare @elements QBM_YCursorBuffer declare @ElementCount int declare @ElementIndex int declare @JournalMessage nvarchar(1000) declare3 @DebugLevel varchar(1) = 'I' declare @MessageType varchar(1) = 'I' declare @ErrorMessage nvarchar(4000) declare @ErrorSeverity int declare @ErrorState4 int declare @WarFehlerhaft int = 0 declare @CountElementsChanged int = 0 declare @ErrorBuffer QBM_YSessionError declare @SQL nvarchar(max) SET XACT_ABORT5 OFF BEGIN TRY if exists (select top 1 1 from DialogDatabase d where d.UpdatePhase not in ( 0) ) and @force = 0 begin goto endLabel end insert into @elements6(Ident2) select distinct c.name as TableName from sys.foreign_keys fk join sys.objects c on c.object_id = fk.parent_object_id join sys.objects p on p.object_id7 = fk.referenced_object_id where fk.type = 'F' and (c.name like @TableName ) and (convert(int, fk.is_disabled)) = 1 select @ElementCount = @@ROWCOUNT 8select @ElementIndex = 1 while @ElementIndex <= @ElementCount and @WarFehlerhaft = 0 begin select top 1 @TabAktuell = bu.Ident2 from @elements bu where9 bu.ElementIndex = @ElementIndex BEGIN TRY select @SQL = concat('10 alter Table ', @TabAktuell, ' with nocheck check constraint all ') exec QBM_PExecuteSQLWithRetry_LLP11 @SQLStatement = @SQL , @LockTimeout_ms = 2500 , @MaxWaitTimeForLock_s = 10 , @ProcIDForJournal = default , @HandleErrorSilent = 0 , @ExecuteWithTransact12 = 0 select @CountElementsChanged += 1 END TRY BEGIN CATCH if @HandleErrorSilent = 0 begin exec QBM_PSessionErrorAdd default if dbo.QBM_FGISessionErrorIsDeadlock13(default) = 0 begin insert into @ErrorBuffer (ErrorMessage, ErrorSeverity, ErrorState, ErrorNumber , ProcedureName, ProcedureLine, MessageDate , GenProcID14, RepeatCounter, IsReThrow, SourceCode) select '#LDS#Possible invalid foreign keys, run consistency checks: {0}|', ERROR_SEVERITY(), ERROR_STATE(), 5000015 , ERROR_PROCEDURE() , ERROR_LINE(), GETUTCDATE() , null, 0, 0, null exec QBM_PSessionErrorAdd @ErrorBuffer exec QBM_PJournal 'SessionError', @@procid,16 'E', @DebugLevel, 20 end end select @WarFehlerhaft = 1 END CATCH select @ElementIndex += 1 end if @CountElementsChanged > 0 and exists (select top 171 1 from sys.objects o where o.name = 'QBM_PJournal' and type = 'P' ) begin select @JournalMessage = '#LDS#System elements modified by {0}, pattern {1}, elements affected {2}.|'18 + isnull(OBJECT_NAME(@@procid), '') + '|' + @TableName + '|' + dbo.QBM_FCVIntToString(@CountElementsChanged) + '|' if not exists (select top 1 1 from19 DialogDatabase where IsMainDatabase = 1 and UpdatePhase <> 0) and not exists (select top 1 1 from sys.tables t with (readpast) join sys.columns c with20 (readpast) on t.object_id = c.object_id where t.name = 'DialogDatabase' and c.name = 'InitialMigrationRunning' ) begin exec QBM_PJournal @JournalMessage21, @@procid, @MessageType, @DebugLevel, 20 end else begin exec QBM_PJournal @JournalMessage, @@procid, 'I', 'I' end end exec QBM_PIndicatorChange 1 END22 TRY BEGIN CATCH exec QBM_PSessionErrorAdd default declare @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow() RAISERROR (@Rethrow, 18, 1) WITH NOWAIT23 END CATCH endLabel: return (@WarFehlerhaft) end 24