SQL Get Object Definition

MSSQL

There are several methods (sp_help and object_definition) for getting definitions for stored procedures and other procedural objects in SQL. One problem I’ve had with them is getting the definitions for very long routines. This seems to be due to the definition spanning more than one sys.syscomments rows.

This simple routine will return your object definition regardless of its length. I use a print as it isn’t limited to its result length.

Declare @def Varchar(max) = ''

Select @def = @def + coalesce(text, '')
FROM sys.syscomments
WHERE id = object_id('mystoredprocedurename')
Order By colid

print @def
About these ads
1 comment

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: