IntroductionIn this article I describe how to drop all the Stored Procedures in a particular database. Several times in our project we needed to drop all Stored Procedures. If there is a large number of Stored Procedures then it is very tedious to drop all of them. Here I explain how to drop all Stored Procedures in a database automatically.I assume you have a basic knowledge of Stored Procedures and cursors; for more help you can visit:
Stored Procedure in SQL Server 2012Cursor in SQL Server 2012First of all we create a table.Creation of Table:create table emp(empId int, empName varchar(15))goinsert into empselect 1,'Deepak'union allselect 2,'Arora'goselect * from empOutput:Now we Create two Stored Procedures.Creation of the first Stored Procedure:create proc usp_selectasselect * from empgoexec usp_selectOutput:Creation of the second Stored Procedure:create proc usp_insert(@id int, @name varchar(15))asinsert into emp values (@id, @name)goexec usp_insert 3,'Daljeet singh'goexec usp_selectOutput:Now we Create a Cursor; see:declare cur_dropProc cursorscroll forselect [name] from sysobjects where xtype='p'Now run the following code:open cur_dropProcgoDeclare @procName varchar(500)fetch first from cur_dropProc into @procNamewhile @@fetch_status=0beginExec('drop procedure ' + @procName)fetch next from cur_dropProc into @procNameendgoclose cur_dropProcgodeallocate cur_dropProcOutput:Now see the Stored Procedure in the Database:select [name] from sysobjects where xtype='p'Output:Summary:In this article I described how to drop all the Stored Procedures in a database in SQL Server. I hope this article has helped you to understand this topic. Please share if you know more about this. Your feedback and constructive contributions are welcome.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: