sp_help (Transact-SQL)
TOC
Collapse the table of content
Expand the table of content

sp_help (Transact-SQL)

 

Reports information about a database object (any object listed in the sys.sysobjects compatibility view), a user-defined data type, or a data type.

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database.

Topic link icon Transact-SQL Syntax Conventions

  
sp_help [ [ @objname = ] 'name' ]  

[ @objname=] 'name'
Is the name of any object, in sysobjects or any user-defined data type in the systypes table. name is nvarchar(776), with a default of NULL. Database names are not acceptable.

0 (success) or 1 (failure)

The result sets that are returned depend on whether name is specified, when it is specified, and what database object it is.

  1. If sp_help is executed with no arguments, summary information of objects of all types that exist in the current database is returned.

    Column nameData typeDescription
    Namenvarchar(128)Object name
    Ownernvarchar(128)Object owner (This is the database principal that owns object. Defaults to the owner of the schema that contains the object.)
    Object_typenvarchar(31)Object type
  2. If name is a SQL Server data type or user-defined data type, sp_help returns this result set.

    Column nameData typeDescription
    Type_namenvarchar(128)Data type name.
    Storage_typenvarchar(128)SQL Server type name.
    LengthsmallintPhysical length of the data type (in bytes).
    PrecintPrecision (total number of digits).
    ScaleintNumber of digits to the right of the decimal.
    Nullablevarchar(35)Indicates whether NULL values are allowed: Yes or No.
    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.
    CollationsysnameCollation of the data type. NULL for non-character data types.
  3. If name is any database object other than a data type, sp_help returns this result set and also additional result sets, based on the type of object specified.

    Column nameData typeDescription
    Namenvarchar(128)Table name
    Ownernvarchar(128)Table owner
    Typenvarchar(31)Table type
    Created_datetimedatetimeDate table created

    Depending on the database object specified, sp_help returns additional result sets.

    If name is a system table, user table, or view, sp_help returns the following result sets. However, the result set that describes where the data file is located on a file group is not returned for a view.

    • Additional result set returned on column objects:

      Column nameData typeDescription
      Column_namenvarchar(128)Column name.
      Typenvarchar(128)Column data type.
      Computedvarchar(35)Indicates whether the values in the column are computed: Yes or No.
      LengthintColumn length in bytes.

      Note: If the column data type is a large value type (varchar(max), nvarchar(max), varbinary(max), or xml), the value will display as -1.
      Precchar(5)Column precision.
      Scalechar(5)Column scale.
      Nullablevarchar(35)Indicates whether NULL values are allowed in the column: Yes or No.
      TrimTrailingBlanksvarchar(35)Trim the trailing blanks. Returns Yes or No.
      FixedLenNullInSourcevarchar(35)For backward compatibility only.
      CollationsysnameCollation of the column. NULL for noncharacter data types.
    • Additional result set returned on identity columns:

      Column nameData typeDescription
      Identitynvarchar(128)Column name whose data type is declared as identity.
      SeednumericStarting value for the identity column.
      IncrementnumericIncrement to use for values in this column.
      Not For ReplicationintIDENTITY property is not enforced when a replication login, such as sqlrepl, inserts data into the table:

      1 = True

      0 = False
    • Additional result set returned on columns:

      Column nameData typeDescription
      RowGuidColsysnameName of the global unique identifier column.
    • Additional result set returned on filegroups:

      Column nameData typeDescription
      Data_located_on_filegroupnvarchar(128)Filegroup in which the data is located: Primary, Secondary, or Transaction Log.
    • Additional result set returned on indexes:

      Column nameData typeDescription
      index_namesysnameIndex name.
      Index_descriptionvarchar(210)Description of the index.
      index_keysnvarchar(2078)Column names on which the index is built. Returns NULL for xVelocity memory optimized columnstore indexes.
    • Additional result set returned on constraints:

      Column nameData typeDescription
      constraint_typenvarchar(146)Type of constraint.
      constraint_namenvarchar(128)Name of the constraint.
      delete_actionnvarchar(9)Indicates whether the DELETE action is: NO_ACTION, CASCADE, SET_NULL, SET_DEFAULT, or N/A.

      Only applicable to FOREIGN KEY constraints.
      update_actionnvarchar(9)Indicates whether the UPDATE action is: NO_ACTION, CASCADE, SET_NULL, SET_DEFAULT, or N/A.

      Only applicable to FOREIGN KEY constraints.
      status_enabledvarchar(8)Indicates whether the constraint is enabled: Enabled, Disabled, or N/A.

      Only applicable to CHECK and FOREIGN KEY constraints.
      status_for_replicationvarchar(19)Indicates whether the constraint is for replication.

      Only applicable to CHECK and FOREIGN KEY constraints.
      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.
    • Additional result set returned on referencing objects:

      Column nameData typeDescription
      Table is referenced bynvarchar(516)Identifies other database objects that reference the table.
    • Additional result set returned on stored procedures, functions, or extended stored procedures.

      Column nameData typeDescription
      Parameter_namenvarchar(128)Stored procedure parameter name.
      Typenvarchar(128)Data type of the stored procedure parameter.
      LengthsmallintMaximum physical storage length, in bytes.
      PrecintPrecision or total number of digits.
      ScaleintNumber of digits to the right of the decimal point.
      Param_ordersmallintOrder of the parameter.

The sp_help procedure looks for an object in the current database only.

When name is not 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 does not expose information about XML indexes or spatial indexes.

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.

A. Returning information about all objects

The following example lists information about each object in the master database.

USE master;  
GO  
EXEC sp_help;  
GO  

B. Returning information about a single object

The following example displays information about the Person table.

USE AdventureWorks2012;  
GO  
EXEC sp_help 'Person.Person';  
GO  

Database Engine Stored Procedures (Transact-SQL)
sp_helpindex (Transact-SQL)
sp_helprotect (Transact-SQL)
sp_helpserver (Transact-SQL)
sp_helptrigger (Transact-SQL)
sp_helpuser (Transact-SQL)
System Stored Procedures (Transact-SQL)
sys.sysobjects (Transact-SQL)

Community Additions

ADD
Show:
© 2016 Microsoft