Skip to main content

SQL Built-In Stored Procedures

Overview

Use built-in stored procedures to perform administrative and informational activities in Microsoft® SQL Server™.

Details

Here are some examples of built-in stored procedures to get you started.

Stored Procedure Syntax

sp_depends - Displays information about database object dependencies (for example, the views and procedures that depend on a table or view, and the tables and views that are depended on by the view or procedure). References to objects outside the current database are not reported.

sp_depends [ @objname = ] 'object'
sp_depends can be used to show relationships between stored procedures, views and tables

sp_help - Reports information about a database object (any object listed in the sysobjects table), a user-defined data type, or a data type supplied by Microsoft® SQL Server™.

sp_help [ [ @objname = ] name ].
sp_help can be used to give you a listing of the columns in a table

sp_datatype_info - Returns information about the data types supported by the current environment.

sp_datatype_info [ [ @data_type = ] data_type ]
     [  [ @ODBCVer = ] odbc_version ]

sp_datatype_info
sp_datatype_info can be useful when designing a new table or adding a column to an existing table to determine the appropriate data type for your field definition.

sp_updatestats - Runs UPDATE STATISTICS against all user-defined tables in the current database.

sp_updatestats [[@resample =] 'resample']
Return Code Values
0 (success) or 1 (failure)
sp_updatestats can be used to optimize the database for better performance

sp_who - Provides information about current Microsoft® SQL Server™ users and processes. The information returned can be filtered to return only those processes that are not idle.

sp_who [[@login_name =] 'login']
sp_who can be used to tell you who is logged into a database

sp_helptext - 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.

sp_helptext [ [ @objname = ] name ].
sp_helptext can be used to provide the definition of a stored procedure that you are troubleshooting.