Microsoft SQL Server – improve SQL Server performance with a simple query

mswindows_logo.jpg   Run this query on a Microsoft SQL Server 2005 or later and it will list indexes that you could create to improve the query performance of your database based on the workload of the server since the SQL service last restarted

SELECT    ‚CREATE INDEX IX_Auto_‘ +
CONVERT(varchar(max), MID.index_handle) +
‚ ON ‚ +
[statement] +
‚ (‚ +
COALESCE(equality_columns + ‚, ‚ + inequality_columns, equality_columns, inequality_columns) +
‚)‘ +
ISNULL(‚ INCLUDE (‚ + included_columns + ‚)‘, “) AS create_statement,
CONVERT(int, avg_total_user_cost * user_seeks * avg_user_impact) AS potential_saving,
[statement] AS table_name,
equality_columns,
inequality_columns,
included_columns,
last_user_seek,
avg_total_user_cost,
user_seeks,
avg_user_impact
FROM      sys.dm_db_missing_index_details MID
JOIN      sys.dm_db_missing_index_groups MIG ON MIG.index_handle = MID.index_handle
JOIN      sys.dm_db_missing_index_group_stats MIGS on MIGS.group_handle = MIG.index_group_handle
ORDER BY  avg_total_user_cost * user_seeks * avg_user_impact DESC

Leave a Reply

You must be logged in to post a comment.