21 April 2011

How to delete all stored procedure in your SQL

This might come in handy one day.
especially when too many sp in our database and we want to drop them all.

Create Procedure dbo.DeleteAllProcedures
As
declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'p'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
if @procName <> 'DeleteAllProcedures'
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur
Go

No comments:

Post a Comment

Twiit.. Twiit... Gulp