Delete / Drop all stored procedures in an SQL Database

The following SQL will delete all stored procedures in a specified database.
Make sure you specify the database you are using!

USE [MyDatabase]
DECLARE @spName varchar(500)
DECLARE _CurCursor CURSOR
 FOR SELECT [name] FROM sys.objects WHERE type = 'p'
 OPEN _CurCursor
 FETCH NEXT FROM _CurCursor INTO @spName
 WHILE @@fetch_status = 0
 BEGIN
 EXEC('DROP PROCEDURE ' + @spName)
 FETCH NEXT FROM _CurCursor INTO @spName
 END
CLOSE _CurCursor
DEALLOCATE _CurCursor

Sorry that it lacks formatting, though it should work with just a copy and paste

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>