Currently we use separate a drop statements for each stored procedure in the script file:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N\'[
By mixing the cursor and system procedure, we would have a optimized solution, as follow:
DECLARE DelAllProcedures CURSOR
FOR
SELECT name AS procedure_name
FROM sys.procedures;
OPEN DelAllProcedures
DECLARE @ProcName VARCHAR(100)
FETCH NEXT
FROM DelAllProcedures
INTO @ProcName
WHILE @@FETCH_STATUS!=-1
BEGIN
DECLARE @command VARCHAR(100)
SET @command=''
SET @command=@command+'DROP PROCEDURE '+@ProcName
--DROP PROCEDURE @ProcName
EXECUTE (@command)
FETCH NEXT
FROM DelAllProcedures
INTO @ProcName
END
CLOSE DelAllProcedures
DEALLOCATE DelAllProcedures