Delete All Stored Procedures and Views in SQL

July 17, 2010 by: Sanket

 

Delete All Stored Procedures

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 curdeallocate cur

Delete All Views

declare @procName varchar(500)declare cur cursor    for select [name] from sys.objects where type = 'v'open cur

fetch next from cur into @procName      while @@fetch_status = 0      begin                  exec('drop view ' + @procName)                  fetch next from cur into @procName      endclose curdeallocate cur

Leave a Reply

*