sp_helptext (Transact-SQL) Home
SQL Server 2008 Books Online (October 2009)
sp_helptext (Transact-SQL)

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.

Topic link icon Transact-SQL Syntax Conventions

Syntax

sp_helptext [ @objname = ] 'name' [ , [ @columnname = ] computed_column_name ]
Arguments

[ @objname = ] 'name'

Is the qualified or nonqualified name of a user-defined, schema-scoped object. Quotation marks are required only if a qualified object is specified. If a fully qualified name, including a database name, is provided, the database name must be the name of the current database. The object must be in the current database. name is nvarchar(776), with no default.

[ @columnname = ] 'computed_column_name'

Is the name of the computed column for which to display definition information. The table that contains the column must be specified as name. column_name is sysname, with no default.

Return Code Values

0 (success) or 1 (failure)

Result Sets

Column name Data type Description

Text

nvarchar(255)

Object definition

Remarks

sp_helptext displays the definition that is used to create an object in multiple rows. Each row contains 255 characters of the Transact-SQL definition. The definition resides in the definition column in the sys.sql_modules catalog view.

Permissions

Requires membership in the public role. System object definitions are publicly visible. The definition of user objects is visible to the object owner or grantees that have any one of the following permissions: ALTER, CONTROL, TAKE OWNERSHIP, or VIEW DEFINITION.

Examples

A. Displaying the definition of a trigger

The following example displays the definition of the uBillOfMaterials trigger in the AdventureWorks database.

USE AdventureWorks;
GO
EXEC sp_helptext 'Production.uBillOfMaterials';
GO

B. Displaying the definition of a computed column

The following example displays the definition of the computed column TotalDue on the SalesOrderHeader table in the AdventureWorks database.

USE AdventureWorks;
GO
sp_helptext @objname = N'AdventureWorks.Sales.SalesOrderHeader', @columnname = TotalDue ;
GO

Here is the result set.

Text
--------------------------------------------
(isnull(([SubTotal]+[TaxAmt])+[Freight],(0)))
See Also

Reference

Database Engine Stored Procedures (Transact-SQL)
OBJECT_DEFINITION (Transact-SQL)
sp_help (Transact-SQL)
sys.sql_modules (Transact-SQL)
System Stored Procedures (Transact-SQL)

Help and Information

Getting SQL Server 2008 Assistance
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View