Powered by Blogger.

Saturday, February 15, 2014

Delete all stored procedures at once in SQL Server database



In this post we will about how to delete all stored procedures at once in SQL Server 2008 database. Also you can check out my previous posts on:

- asp.net mvc 4 tutorial

- How to get Column names of table in SQL Server 2008?

- Cookieless session in Asp.Net

There different approach to delete all stored procedures in SQL Server 2008.

Approach-1:

SELECT 'DROP PROCEDURE ' + p.NAME
FROM sys.procedures p

The above command will generate the DROP PROCEDURE statement like below:


And then you can copy those statements and put it in a new query window and run the commands.

Approach-2:

DECLARE @procedureName varchar(500)
DECLARE cur CURSOR 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

Hope it will work for you.





0 comments

Post a Comment