Update statistics of all tables in SQL Server 2008/2005

Today I am going to share very small yet very useful and handy script. It is often necessary to keep update statistics of all tables for performance point of view. Actually by default query optimizer updates statistics in query plan in certain situation but it is good to manually do it to assure that every query plan it optimized and up-to-date.

You can generate T-SQL for update statistics for all tables of your database along with Schema name. Have a look at the script.

        ‘UPDATE STATISTICS ‘ + SysSche.Name + ‘.’ + SysObj.Name
        Sys.Objects SysObj
        sys.schemas SysSche ON SysObj.Schema_ID = SysSche.Schema_ID
        TYPE = ‘U’

For more details about UPDATE STATESTICS and its syntax, you can refer official Microsoft link at



Reference: Ritesh Shah
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: