Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Reports information about a database object (any object listed in the sys.sysobjects compatibility view), a user-defined data type, or a data type.
Transact-SQL syntax conventions
Syntax
sp_help [ [ @objname = ] N'objname' ]
[ ; ]
Arguments
[ @objname = ] N'objname'
The name of any object, in sys.sysobjects or any user-defined data type in the sys.systypes table. @objname is nvarchar(776), with a default of NULL. Database names aren't acceptable. Two or three part names might be delimited, such as Person.AddressType or [Person].[AddressType].
Return code values
0 (success) or 1 (failure).
Result set
The result sets that are returned depend on whether @name is specified, when it's specified, and which database object it is.
If
sp_helpis executed with no arguments, summary information of objects of all types that exist in the current database is returned.Column name Data type Description Namenvarchar(128) Object name Ownernvarchar(128) Object owner (The database principal that owns object. Defaults to the owner of the schema that contains the object.) Object_typenvarchar(31) Object type If @name is a SQL Server data type or user-defined data type,
sp_helpreturns this result set.Column name Data type Description Type_namenvarchar(128) Data type name. Storage_typenvarchar(128) SQL Server type name. Lengthsmallint Physical length of the data type (in bytes). Precint Precision (total number of digits). Scaleint Number of digits to the right of the decimal. Nullablevarchar(35) Indicates whether NULLvalues are allowed:YesorNo.Default_namenvarchar(128) Name of a default bound to this type. NULL= No default is bound.Rule_namenvarchar(128) Name of a rule bound to this type. NULL= No default is bound.Collationsysname Collation of the data type. NULLfor non-character data types.If @name is any database object other than a data type,
sp_helpreturns this result set and also additional result sets, based on the type of object specified.Column name Data type Description Namenvarchar(128) Table name Ownernvarchar(128) Table owner Typenvarchar(31) Table type Created_datetimedatetime Date table created Depending on the database object specified,
sp_helpreturns additional result sets.If @name is a system table, user table, or view,
sp_helpreturns the following result sets. However, the result set that describes where the data file is located on a file group isn't returned for a view.The following result set is also returned on column objects:
Column name Data type Description Column_namenvarchar(128) Column name. Typenvarchar(128) Column data type. Computedvarchar(35) Indicates whether the values in the column are computed: YesorNo.Lengthint Column length in bytes.
Note: If the column data type is a large value type (varchar(max), nvarchar(max), varbinary(max), or xml), the value displays as-1.Precchar(5) Column precision. Scalechar(5) Column scale. Nullablevarchar(35) Indicates whether NULLvalues are allowed in the column:YesorNo.TrimTrailingBlanksvarchar(35) Trim the trailing blanks. Returns YesorNo.FixedLenNullInSourcevarchar(35) This parameter is deprecated and is maintained for backward compatibility of scripts. Collationsysname Collation of the column. NULLfor noncharacter data types.The following result set is also returned on identity columns:
Column name Data type Description Identitynvarchar(128) Column name whose data type is declared as identity. Seednumeric Starting value for the identity column. Incrementnumeric Increment to use for values in this column. Not For Replicationint IDENTITYproperty isn't enforced when a replication login, such as sqlrepl, inserts data into the table:1= True0= FalseThe following result set is also returned on columns:
Column name Data type Description RowGuidColsysname Name of the global unique identifier column. The following result set is also returned on filegroups:
Column name Data type Description Data_located_on_filegroupnvarchar(128) Filegroup in which the data is located: Primary,Secondary, orTransaction Log.The following result set is also returned on indexes:
Column name Data type Description index_namesysname Index name. Index_descriptionvarchar(210) Description of the index. index_keysnvarchar(2078) Column names on which the index is built. Returns NULLfor memory optimized columnstore indexes.The following result set is also returned on constraints:
Column name Data type Description constraint_typenvarchar(146) Type of constraint. constraint_namenvarchar(128) Name of the constraint. delete_actionnvarchar(9) Indicates whether the DELETEaction is one ofNO_ACTION,CASCADE,SET_NULL,SET_DEFAULT, orN/A.
Only applicable to FOREIGN KEY constraints.update_actionnvarchar(9) Indicates whether the UPDATEaction is one ofNO_ACTION,CASCADE,SET_NULL,SET_DEFAULT, orN/A.
Only applicable toFOREIGN KEYconstraints.status_enabledvarchar(8) Indicates whether the constraint is enabled: Enabled,Disabled, orN/A.
Only applicable toCHECKandFOREIGN KEYconstraints.status_for_replicationvarchar(19) Indicates whether the constraint is for replication.
Only applicable toCHECKandFOREIGN KEYconstraints.constraint_keysnvarchar(2078) Names of the columns that make up the constraint or, in the case for defaults and rules, the text that defines the default or rule. The following result set is also returned on referencing objects:
Column name Data type Description Table is referenced bynvarchar(516) Identifies other database objects that reference the table. The following result set is also returned on stored procedures, functions, or extended stored procedures.
Column name Data type Description Parameter_namenvarchar(128) Stored procedure parameter name. Typenvarchar(128) Data type of the stored procedure parameter. Lengthsmallint Maximum physical storage length, in bytes. Precint Precision or total number of digits. Scaleint Number of digits to the right of the decimal point. Param_ordersmallint Order of the parameter.
Remarks
The sp_help procedure looks for an object in the current database only.
When @name isn't specified, sp_help lists object names, owners, and object types for all objects in the current database. sp_helptrigger provides information about triggers.
sp_help exposes only orderable index columns; therefore, it doesn't expose information about XML indexes or spatial indexes.
Permissions
Requires membership in the public role. The user must have at least one permission on @objname. To view column constraint keys, defaults, or rules, you must have VIEW DEFINITION permission on the table.
Examples
The code samples in this article use the AdventureWorks2022 or AdventureWorksDW2022 sample database, which you can download from the Microsoft SQL Server Samples and Community Projects home page.
A. Return information about all objects
The following example lists information about each object in the master database.
USE master;
GO
EXECUTE sp_help;
GO
B. Return information about a single object
The following example displays information about the Person.Person table.
USE AdventureWorks2022;
GO
EXECUTE sp_help 'Person.Person';
GO