Update statistics for all user database | SansSQL

Thursday, September 20, 2012

Update statistics for all user database

In one of my previous post "What is Statistics in SQL Server", I had explained about what is Statistics.
Today, I am posting a Query which will update statistics on all user database in that Instance.

EXEC sp_MSForeachdb 'USE [?];
IF ''?'' not in (''master'',''model'',''msdb'',''tempdb'',''distribution'') 
 AND DATABASEPROPERTYEX(''?'',''Updateability'') = ''READ_WRITE''
Print ''Updating statistics for database "'' + ''?'' + ''"''
EXEC sp_updatestats

This Query will exclude the system database and those database which are not in Read_Write status.

No comments:

Post a Comment