Skip to main content

SQL query to get the list of user defined stored procedures in SQL Server

To get the list of all Stored procedures written by user for its database operation, following query is useful.

select * from [myDataBaseName].sys.procedures where is_ms_shipped = 0
order by name



If you want to get the all list of stored procedures just use the following query.

SELECT NAME FROM [myDataBaseName].sys.all_objects WHERE type='P'

After getting the required result from database we can make use this result as per our requirement.
If we want to delete/drop all stored procedures we defined previously, just write the cursor to drop the stored procedures from list.

I have written a small cursor to delete user defined stored procedures one-by-one.

--====================================
-- Author : Gajanan
-- Description :
--====================================
create procedure procedure_TODeleteAllSps
as
begin
set nocount on
declare  @ProcName  nvarchar(100)

declare c1 cursor for SELECT name FROM [MydbName].sys.procedures WHERE is_ms_shipped = 0
ORDER BY name
open c1
fetch next from c1 into @ProcName
while @@FETCH_STATUS =0
begin
exec ('drop procedure' + @ProcName)

fetch next from c1 into @ProcName
end
close c1
deallocate c1
end

I hope this post will help you.

Regards,
Gajanan


Popular posts from this blog

Asp.Net Web API

What is ASP.NET Web API? ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.   Difference between ASP.NET Web API and WCF Web AP I is a Framework to build HTTP Services that can reach a board of clients, including browsers, mobile, IoT Devices, etc. and provided an ideal platform for building RESTful applications. It is limited to HTTP based services. ASP.NET framework ships out with the .NET framework and is Open Source. WCF i.e. Windows Communication Foundation is a framework used for building Service Oriented applications (SOA) and supports multiple transport protocol like HTTP, TCP, MSMQ, etc. It supports multiple protocols like HTTP, TCP, Named Pipes, MSMQ, etc. WCF ships out with the .NET Framework. Both Web API and WCF can be self-hosted or can be...