The Database Engine keeps statistics about the distribution of the key values in each index and uses these statistics to determine which index or indexes to use in query processing. Users can create statistics on nonindexed columns by using the CREATE STATISTICS statement. Query optimization depends on the accuracy of the distribution steps:
-
If there is significant change in the key values in the index, rerun UPDATE STATISTICS on that index.
-
If lots of data in an indexed column has been added, changed, or removed (that is, if the distribution of key values has changed), or the table has been truncated by using the TRUNCATE TABLE statement and then repopulated, use UPDATE STATISTICS.
To see when the statistics were last updated, use the STATS_DATE function.
UPDATE STATISTICS WITH RESAMPLE updates all the statistics on a table at the current sampling rate. This means that statistics tied to indexes, which are created with full scan when the index is built, require the whole table scan to be refreshed. This potentially can be a very time consuming operation, especially when it involves large partitioned tables with many indexes. Refreshing each statistic requires reading lots of data. To avoid this problem, consider using sp_updatestats (Transact-SQL). This updates statistics only when they are required.
Statistics can be created or updated on tables with computed columns only if the conditions exist in which an index can be created on these columns. For more information about the requirements and restrictions for creating indexes on computed columns, see CREATE INDEX (Transact-SQL).
If you disable automatic statistics recomputation, you must manually update the statistical information.
Note: |
|---|
|
The UPDATE STATISTICS statement re-enables automatic statistical updating on the target table or view unless the NORECOMPUTE clause is specified.
|