2011-03-20

Update your statistics

If your database suffers of poor performances, before you try any optimization, you should update all statistics. Otherwise SQL Server will produce suboptimal plans.
Out of there a lot of databases have no maintenance plan simply because no one is in charge of it.


This simple query will generete the script for you.


SELECT 'UPDATE STATISTICS [' + SCHEMA_NAME(T.schema_id) + '].[' + T.name + ']'
FROM sys.tables T
WHERE NOT EXISTS
    ( SELECT TOP 1 1
     FROM sys.extended_properties EP
     WHERE EP.major_id = T.object_id
       AND EP.name = 'microsoft_database_tools_support' )
  AND T.is_ms_shipped = 0
ORDER BY 1

No comments:

Post a Comment