Version: SQLServer 8
I would like to view the contents of a stored function in sqlserver, i.e. what exactly the function is doing.
None of the options listed
You can use sp_helptext command to view the definition. It simply does
Displays the definition of a user-defined rule, default, unencrypted Transact-SQL stored procedure, user-defined Transact-SQL function, trigger, computed column, CHECK constraint, view, or system object such as a system stored procedure.
E.g;
EXEC sp_helptext 'StoredProcedureName'
EDIT:
If your databases
or server
are different then you can do it by specifying them as well
EXEC [ServerName].[DatabaseName].dbo.sp_helptext 'storedProcedureName'
select definition
from sys.sql_modules
where object_name(object_id) like 'functionName'
Whether it is Stored Procedure OR Function OR any SQL object below script will give the full definition
USE<Your Data base>
SELECT OBJECT_DEFINITION (OBJECT_ID('<YOUR OBJECT NAME>')) AS ObjectDefinition
where OBJECT NAME could be your object name such as Stored Procedure / Function / Trigger ...etc name
You can go to Object Explorer, choose the Database containing the Stored Procedure and then choose 'Script Stored Procedure As ':
And then check in the destination folder you chose.
Yes it is working fine.
To view the stored procedures... SELECT * FROM sys.procedures;
and get procduere name and use the below query for the same(I'm using SQuirreL SQL Client Version 3.2.0-RC1).
EXEC sp_helptext 'StoredProcedureName'.
I rather use INFORMATION_SCHEMA.ROUTINES:
select ROUTINE_NAME, ROUTINE_DEFINITION, LAST_ALTERED
from INFORMATION_SCHEMA.ROUTINES where SPECIFIC_NAME = 'usp_mysp'
Just copy the ROUTINE_DEFINITION column to a new window to see the full content.