Updating statistics
This topic describes when to update statistics and provides an
example.
Note: This topic applies only to on-premises
environments.
Use the Transact-SQL statement UPDATE STATISTICS
if these
events occur:
- A process suddenly takes much longer than usual to run.
- There is a significant change in the key values in an index.
- A large amount of data in an indexed column has been added,
changed, or removed, or the table has been truncated using the
TRUNCATE TABLE
statement and then repopulated.
We recommend that you update statistics nightly or weekly.
This example updates the statistics for all indexes on the customer table:
UPDATE STATISTICS customer
To update statistics for all tables in the in the current database, you can
run the SQL Server stored procedure sp_updatestats
, which uses UPDATE
STATISTICS
:
EXEC sp_updatestats
For more information, see SQL Server help for UPDATE
STATISTICS
and sp_updatestats
.