Get Definition For Stored Procedures, UDFs, And Triggers Using T-SQL Statement

sqlserver2012

You want to use Transact-SQL to list the definition for a stored procedure, User Defined Function, or Trigger? You can use one of the following ways:

Solution 1: sp_helptext (T-SQL)

sp_helptext ‘dbo.your_object_name’

Solution 2: syscomments (T-SQL)

SELECT [text]
FROM sys.syscomments
WHERE OBJECT_NAME(id) = ‘your_object_name’

Solution 3: OBJECT_DEFINITION (T-SQL)

SELECT OBJECT_DEFINITION(OBJECT_ID(‘your_object_name’))

Solution 4: Sys.Sql_Modules (T-SQL)

SELECT definition
FROM sys.sql_modules
WHERE object_id = (OBJECT_ID(N’your_object_name’));
Advertisements

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