ALTER PROCEDURE [dbo].[procUtils_ForEachProcedure]
WITH EXECUTE AS CALLER
AS
BEGIN -- proc start
SET NOCOUNT ON;
BEGIN TRY --begin try
declare @LogLevel int --THE LOG LEVEL OF THE EXECUTING USER
declare @ProcedureName varchar(1000) --
DECLARE @CODESTR VARCHAR(MAX)
--Declare the Procedure variable
DECLARE @ProcedureNames Table
(
Number INT IDENTITY(1,1), --Auto incrementing Identity column
ProcedureName VARCHAR(300) --The string value
)
--Decalre a variable to remember the position of the current delimiter
DECLARE @CurrentDelimiterPositionVar INT
--Decalre a variable to remember the number of rows in the Procedure
DECLARE @Count INT
DECLARE @SqlCode varchar(200)
-- DEBUG select * from sys.procedures
--Populate the Procedure variable using some logic
INSERT INTO @ProcedureNames
SELECT name FROM sys.procedures
--where name like '%procGen%' --ADD SOME CONSTRAINT ALSO ...
--Initialize the looper variable
SET @CurrentDelimiterPositionVar = 1
--Determine the number of rows in the Procedure
SELECT @Count=max(Number) from @ProcedureNames
--Loop through until all row processing is done
WHILE @CurrentDelimiterPositionVar <= @Count
BEGIN
SET @CODESTR = 'DROP '
--Load current value from the Procedure
SELECT @ProcedureName = ProcedureName FROM @ProcedureNames WHERE Number = @CurrentDelimiterPositionVar
--Process the current value
SET @CODESTR = @CODESTR + 'PROC '+ @ProcedureName + ''
print @CODESTR
--Increment loop counter
SET @CurrentDelimiterPositionVar = @CurrentDelimiterPositionVar + 1;
END
END TRY --end try
BEGIN CATCH
print ' Error number: ' + CAST(ERROR_NUMBER() AS varchar(100)) +
'Error message: ' + ERROR_MESSAGE() + 'Error severity: ' +
CAST(ERROR_SEVERITY() AS varchar(10)) +
'Error state: ' + CAST(ERROR_STATE() AS varchar(1000)) +
'XACT_STATE: ' + CAST(XACT_STATE() AS varchar(1000))
END CATCH
END --procedure end
/*
USE [Db]
GO
exec procUtils_ForEachProcedure
*/
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!