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.

This site uses Akismet to reduce spam. Learn how your comment data is processed.