sp_helpstats

Transact-SQL Reference

Transact-SQL Reference

sp_helpstats

Returns statistics information about columns and indexes on the specified table.

Syntax

sp_helpstats[ @objname = ] 'object_name'
    [ , [ @results = ] 'value' ]

Arguments

[@objname =] 'object_name'

Specifies the table on which to provide statistics information. object_name is nvarchar(520) and cannot be null.

[@results =] 'value'

Specifies the extent of information to provide. Valid entries are ALL and STATS. ALL lists statistics for all indexes as well as columns that have statistics created on them; STATS only lists statistics not associated with an index. value is nvarchar(5) with a default of STATS.

Return Code Values

0 (success) or 1 (failure)

Result Sets

This table describes the columns in the result set.

Column name Description
statistics_name The name of the statistics. Returns sysname and cannot be null.
statistics_keys The keys on which statistics are based. Returns nvarchar(2078) and cannot be null.

Remarks

Use DBCC SHOW_STATISTICS to display detailed statistics information about any particular index or statistics. In SQL Server 7.0 Books Online, see DBCC SHOW_STATISTICS and sp_helpindex for related information.

Permissions

Execute permissions default to the public role.

Examples

Create single-column statistics for all eligible columns for all user tables in the Northwind database by executing sp_createstats. To find out the resultant statistics created on the Customers table, execute sp_helpstats.

This table lists the contents of the result set.

statistics_name statistics_keys
PK_Customers CustomerID
City City
CompanyName CompanyName
PostalCode PostalCode
Region Region
ContactName ContactName
ContactTitle ContactTitle
Address Address
Country Country
Phone Phone
Fax Fax