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

About these ads

2 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 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?

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 2,131 other followers

%d bloggers like this: