Delete all procedures from Database Sql Server

Today we will discuss regarding sql server’s tutorial, how to delete all procedures from database sql server. There are many ways to delete all procedures from Database sql server, lets take some examples which are as followed:

Delete all procedures from Database Sql Server example-1:

declare @procedureName varchar(500)
declare cur cursor 

-- Select all the procedures from sys.object table.
for select [name] from sys.objects where type = 'p'
open cur
fetch next from cur into @procedureName
while @@fetch_status = 0
begin
    exec('drop procedure ' + @procedureName)
    fetch next from cur into @procedureName
end
close cur
deallocate cur

Delete all procedures from Database Sql Server example-2:

  • First generate the list of stored procedures to dropĀ procedures:
    -- Get list procedure list from sys.procedures
    SELECT 'DROP PROCEDURE [' + SCHEMA_NAME(p.schema_id) + '].[' + p.NAME + ']'
    FROM sys.procedures p

    This generates a list of Drop ProcedureĀ statements in your SSMS output window.

  • copy that list into a new query window and execute it

These are two ways which I know to Delete all procedures from Database Sql Server. Please share your sql query, if there is another possible way to achieve this task.

Happy Coding… šŸ™‚

 

Leave a Reply