If you want to list the definition for a stored procedure, User Defined Function, or Trigger, you can use one of the following ways:
Alternative 1: sp_helptext (T-SQL)
-- using sp_helptext sp_helptext 'dbo.your_object_name'
Alternative 2: syscomments (T-SQL)
-- using syscomments SELECT 1 FROM sys.syscomments WHERE OBJECT_NAME(id) = 'your_object_name'
Alternative 3: OBJECT_DEFINITION (T-SQL)
-- using built in function OBJECT_DEFINITION SELECT OBJECT_DEFINITION(OBJECT_ID('your_object_name'))How to Get Definition for Stored Procedures, UDFs and Triggers using T-SQL,
Filed under:
DBA Toolbox / T-SQL Scripts, T-SQL Tips and Tricks
[…] How to Get Definition for Stored Procedures, UDFs and Triggers using T-SQL … […]
syscomments truncates to 4000 chars.
SELECT definition
FROM sys.sql_modules
WHERE object_id = (OBJECT_ID(N’your_object_name’));