This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing scripts to update a statistic of an individual object or all the objects in SQL Server.
In the query execution process, Query Optimizer uses a statistic of objects to get different information like: number of actual rows, index information, data change count and others.
The database statistic helps to the Query Optimizer in choosing a best execution plan for query processing.
Why object statistic should be updated?
The Query Optimer choose an execution plan accordingly statistical data.
For example, Your table has an actual row count is 100000 and imagine that statistic object is not updated and has only a 50000 row count, so with this situation, it may be selects a wrong execution plan.
To update a Statistic of Tables and Indexes is also one type of maintenance task for DBA and it should be performed periodically.
Update all statistic of a Database:
1 |
EXEC sp_updatestats; |
1 |
UPDATE STATISTICS Table_Name |
1 |
UPDATE STATISTICS Table_Name Index_Name |