SQL Server: sp_updatestats to update the Database Statistics

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:

Update statistic of a Table:
Update statistic of an Index:
Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of