Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Returns statistics information about columns and indexes on the specified table.
Important
This feature will be removed in a future version of SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. To obtain information about statistics, query the sys.stats and sys.stats_columns catalog views.
Transact-SQL syntax conventions
sp_helpstats
[ @objname = ] N'objname'
[ , [ @results = ] N'results' ]
[ ; ]
Specifies the table on which to provide statistics information. @objname is nvarchar(776), with no default. A one-part or two-part name can be specified.
Specifies the extent of information to provide. @results is nvarchar(5), with a default of STATS
.
ALL
lists statistics for all indexes and also columns that have statistics created on them.STATS
only lists statistics not associated with an index.0
(success) or 1
(failure).
The following table describes the columns in the result set.
Column name | Description |
---|---|
statistics_name |
The name of the statistics. Returns sysname and can't be NULL . |
statistics_keys |
The keys on which statistics are based. Returns nvarchar(2078) and can't be NULL . |
Use DBCC SHOW_STATISTICS
to display detailed statistics information about any particular index or statistics. For more information, see DBCC SHOW_STATISTICS and sp_helpindex.
Requires membership in the public role.
The following example creates single-column statistics for all eligible columns for all user tables in the AdventureWorks2022
database by executing sp_createstats
. Then, sp_helpstats
is run to find the resultant statistics created on the Customer
table.
USE AdventureWorks2022;
GO
EXEC sp_createstats;
GO
EXEC sp_helpstats
@objname = 'Sales.Customer',
@results = 'ALL';
Here's the result set.
statistics_name statistics_keys
---------------------------- ----------------
_WA_Sys_00000003_22AA2996 AccountNumber
AK_Customer_AccountNumber AccountNumber
AK_Customer_rowguid rowguid
CustomerType CustomerType
IX_Customer_TerritoryID TerritoryID
ModifiedDate ModifiedDate
PK_Customer_CustomerID CustomerID
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today