Dropping all non-system Stored Procedures from a Database

Hello Friends,

Here in this post I am sharing SQL statements which delete all the non-system stored procedures  from SQL database.

Your suggestions and views are most welcome.

DECLARE @name VARCHAR(255)
DECLARE @SQL VARCHAR(255)

SELECT @name = (SELECT TOP 1 name FROM sysobjects WHERE [type] = 'P' AND 
category = 0 ORDER BY name)

WHILE @name is not null
BEGIN
    PRINT 'Dropping Procedure : ' + @name
    SELECT @SQL = 'Drop Procedure [dbo].[' + RTRIM(@name) +']'
    EXEC (@SQL)
    PRINT 'Dropped Procedure : ' + @name
    SELECT @name = (SELECT TOP 1 name FROM sysobjects WHERE [type] = 'P' AND 
    category = 0 AND name > @name ORDER BY name)
END
GO

 

Happy Coding

MSCoder

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>