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

Microsoft SQL Server Blog. Fight the fear of SQL with SQLHub.com. Founder is Ritesh Shah