sp_autostats (Transact-SQL)
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 (Transact-SQL) and Statistics.
If stats_flag is specified, sp_autostats reports the action that was taken but returns no result set.
If stats_flag is not specified, sp_autostats returns the following result set.
|
Column name |
Data type |
Description |
|---|---|---|
|
Index Name |
varchar(60) |
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.
A. Display the status of all statistics on a table
The following displays the status of all statistics on the Product table.
USE AdventureWorks2012; GO EXEC sp_autostats 'Production.Product'; GO
B. Enable AUTO_UPDATE_STATISTICS for all statistics on a table
The following enables the AUTO_UPDATE_STATISTICS option for all statistics on the Product table.
USE AdventureWorks2012; GO EXEC sp_autostats 'Production.Product', 'ON'; GO
C. Disable AUTO_UPDATE_STATISTICS for a specific index
The following example disables the AUTO_UPDATE_STATISTICS option for the AK_Product_Name index on the Product table.
USE AdventureWorks2012; GO EXEC sp_autostats 'Production.Product', 'OFF', AK_Product_Name; GO
