SQL Flow Field Guide

sys.sp_helpstats

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

sphelpstats returns statistics information about columns and indexes on the specified table.

What changes

Input
Not stated in the Microsoft summary.
Output or change
Not stated in the Microsoft summary.

Syntax at a glance

sys.sp_helpstats
    [ @objname = ] N'objname'
    [ , [ @results = ] N'results' ]
[ ; ]

Work example

sphelpstats returns statistics information about columns and indexes on the specified table.

Write a proposed call on paper. Name the target, required permission, expected change, and recovery step before any lab use.

Check your work Inspects statistics metadata for the first visible user table that has statistics. The SELECT reads metadata and the procedure call is conditional. Microsoft says this procedure will be removed in a future version.

Practice SQL

Open in SQL Flow

Open the SQL for a walkthrough. Run the example in SQL Server to check its result.

DECLARE @object_name nvarchar(517); SELECT TOP (1) @object_name = QUOTENAME(s.name) + N'.' + QUOTENAME(t.name) FROM sys.tables AS t JOIN sys.schemas AS s ON s.schema_id = t.schema_id JOIN sys.stats AS st ON st.object_id = t.object_id WHERE t.is_ms_shipped = 0 ORDER BY s.name, t.name; IF @object_name IS NOT NULL EXEC sys.sp_helpstats @objname = @object_name, @results = N'ALL'; ELSE SELECT N'No visible user table with statistics in the current database.' AS check_message;

Open Microsoft Learn for full syntax, permissions, and details for your version.