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
Displays or changes the automatic statistics update option, AUTO_UPDATE_STATISTICS
, for an index, a statistics object, a table, or an indexed view.
For more information about the AUTO_UPDATE_STATISTICS
option, see ALTER DATABASE SET options and Statistics.
Transact-SQL syntax conventions
sp_autostats
[ @tblname = ] N'tblname'
[ , [ @flagc = ] 'flagc' ]
[ , [ @indname = ] N'indname' ]
[ ; ]
The name of the table or indexed view for which to display the AUTO_UPDATE_STATISTICS
option. @tblname is nvarchar(776), with no default.
Updates or displays the AUTO_UPDATE_STATISTICS
option. @flagc is varchar(10), and can be one of these values:
Value | Description |
---|---|
ON |
On |
OFF |
Off |
Not specified | Displays the current AUTO_UPDATE_STATISTICS setting |
The name of the statistics for which to display or update the AUTO_UPDATE_STATISTICS
option. @indname is sysname, with a default of NULL
. To display the statistics for an index, you can use the name of the index; an index and its corresponding statistics object have the same name.
0
(success) or 1
(failure).
If @flagc is specified, sp_autostats
reports the action that was taken but returns no result set.
If @flagc isn't specified, sp_autostats
returns the following result set.
Column name | Data type | Description |
---|---|---|
Index Name |
sysname | Name of the index or statistics. |
AUTOSTATS |
varchar(3) | Current value for the AUTO_UPDATE_STATISTICS option. |
Last Updated |
datetime | Date of the most recent statistics update. |
The result set for a table or indexed view includes statistics created for indexes, single-column statistics generated with the AUTO_CREATE_STATISTICS
option and statistics created with the CREATE STATISTICS statement.
If the specified index is disabled, or the specified table has a disabled clustered index, an error message is displayed.
AUTO_UPDATE_STATISTICS
is always OFF for memory-optimized tables.
To change the AUTO_UPDATE_STATISTICS
option, you need membership in the db_owner fixed database role, or ALTER
permission on @tblname.
To display the AUTO_UPDATE_STATISTICS
option, you need membership in the public role.
The following displays the status of all statistics on the Production.Product
table.
USE AdventureWorks2022;
GO
EXEC sp_autostats 'Production.Product';
GO
The following example enables the AUTO_UPDATE_STATISTICS
option for all statistics on the Production.Product
table.
USE AdventureWorks2022;
GO
EXEC sp_autostats 'Production.Product', 'ON';
GO
The following example disables the AUTO_UPDATE_STATISTICS
option for the AK_Product_Name
index on the Production.Product
table.
USE AdventureWorks2022;
GO
EXEC sp_autostats 'Production.Product', 'OFF', AK_Product_Name;
GO
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