How to list source code of store procedures?

To list source code one can call dbo.sp_helptext '<store procedure>' to list code.

Example:
exec dbo.sp_helptext 'sp_databases'

Text
—————————–
create procedure sys.sp_databases
as
set nocount on

select
….

Another way of viewing code is to query syscomments but it doesn’t format the output.
Example:
select so.name, text
FROM syscomments sc, sysobjects so
where so.id = sc.id
and name = 'sp_databases'
order by number, colid

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s