Skip to content

Instantly share code, notes, and snippets.

@kdarty
Last active August 29, 2015 14:03
Show Gist options
  • Save kdarty/eb2e80579b753711f7b4 to your computer and use it in GitHub Desktop.
Save kdarty/eb2e80579b753711f7b4 to your computer and use it in GitHub Desktop.
Drop All Stored Procedures for SQL Server
/******************************************************/
/** Description:Deletes all Stored Procedures in the **/
/** given Database. **/
/** **/
/** WARNING: This can be very Dangerous. Verify **/
/** your current Database connection **/
/** before use. It is recommended to **/
/** enter the Target Database in the **/
/** USE clause. **/
/** **/
/** Source: http://bit.ly/DropAllProcedures **/
/******************************************************/
USE [EnterDatabaseNameForSafety]
DECLARE @procName VARCHAR(500)
DECLARE procCursor CURSOR FOR
SELECT [Name]
FROM sys.objects
WHERE Type = 'p'
OPEN procCursor
FETCH NEXT FROM procCursor INTO @procName
WHILE @@fetch_status = 0
BEGIN
EXEC('drop procedure ' + @procName)
FETCH NEXT FROM procCursor INTO @procName
END
CLOSE procCursor
DEALLOCATE procCursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment