Go to DotNetFunda.com
 Welcome, Guest!  
LoginLogin  
{ Submit content and get exposure !!! }
Submit: Article | Interview Question | Tips | Joke | Question | Link || Search  
 Skip Navigation Links Home > Articles > Getting all stored procedures from a database

All Articles | Post Articles |  Subscribe to RSS

Getting all stored procedures from a database

 Posted on: 7/4/2008 12:12:12 AM by Hardcoder | Views: 782 | Category: Sql Server | Level: Intermediate | Print Article
ASP.NET Hosting with Windows 2008/2003
Hi all,
Here how you can get all the stored procedure from a database. Hey not only the name but the stored procedures definitions also.


Introduction
Hi all,
Here how you can get all the stored procedure from a database. Hey not only the name but the stored procedures definitions also.
Get by using Cursor

declare @proc_name varchar(100)
declare @str_query nvarchar(MAX)

declare loop_proc cursor
for select [name] from sys.procedures where type='P'
and is_ms_shipped = 0
open loop_proc

FETCH NEXT FROM loop_proc INTO @proc_name
IF @@FETCH_STATUS <> 0

PRINT ' <>'
WHILE @@FETCH_STATUS = 0


BEGIN
SELECT @str_query = 'sp_helptext ' + @proc_name
PRINT @str_query
exec sp_executesql @str_query
FETCH NEXT FROM loop_proc INTO @proc_name
END
CLOSE loop_proc
DEALLOCATE loop_proc

Run these sql statements and view the result in Text mode. You will get all scripts for stored procedures.

Get from sysobjects

This is better option to get all stroed procedures from a database.

SELECT [text]
FROM
sysobjects o
JOIN syscomments c ON o.id = c.id
WHERE xtype = 'P'

Conclusion

So you learn how to get all stored procedures from a database, for getting more about sql tricks please visit http://matespoint.blogspot.com/search/label/SQL

 


Interesting?  Bookmark and Share kick it on DotNetKicks.com


Experience:4 year(s)
Home page:http://matespoint.blogspot.com
Member since:Wednesday, June 04, 2008
Biography:Later
 Latest post(s) from Hardcoder

   ◘ Getting all stored procedures from a database posted on 7/4/2008 12:12:12 AM


Response(s) to this Article
Posted by: Deeraj | Posted on: 17 Jul 2008 07:43:36 AM
Here is an easy way to query all stored procedures in SQL Server 2005.

Select routine_name,routine_definition,* from information_schema.routines.

HTH.

Best Regards,
Dheeraj.


About Us | Contact Us | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
All rights reserved to DotNetFunda.com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)