MSSQLWIKI

Karthick P.K on SQL Server

How to rebuild index and update statistics for all the tables in database.

Posted by Karthick P.K on September 26, 2010

 
EXEC sp_MSforeachtable 'UPDATE STATISTICS ? WITH FULLSCAN'   --  {can be run anytime}

Exec sp_MSforeachtable "dbcc dbreindex('?')"      --- {Always run this on a off-peak hour on any SQL Server instance}
 

Thanks

Karthick

3 Responses to “How to rebuild index and update statistics for all the tables in database.”

  1. […] How to rebuild index and update statistics for all the tables in database. […]

  2. saravana's avatar

    saravana said

    Hi Karthick,

    Thanks for the post. i am a new bee sql server admin. When i try to update statistics for the db, the server hangs. So try to update part by part and i found that it is getting stuck in few tables. So i excluded those tables and try to update, it worked. I try to manually update those tables (which hanged), it hangs. Is there any way i can update statistics in those tables?

  3. itats's avatar

    itats said

    It’s difficult to find experienced people about this subject,
    but you sound like you know what you’re talking
    about! Thanks

Leave a reply to Top SQL Server blogs from MSSQLWIKI « MSSQLWIKI Cancel reply