SQL Script to locate fields that should be indexed

Thanks Paul!
And Thanks to the site: http://www.i-programmer.info/programming/database/3208-improve-sql-performance-find-your-missing-indexes.html

SET TRANSACTION ISOLATION LEVEL 
READ UNCOMMITTED;
SELECT TOP 20
       [Total Cost] = ROUND(s.avg_total_user_cost * s.avg_user_impact * (s.user_seeks + s.user_scans), 0)
       ,[Table Name] = d.statement 
       ,d.equality_columns
       ,d.inequality_columns
       ,d.included_columns
       ,d.database_id
FROM
       sys.dm_db_missing_index_groups g
       INNER JOIN sys.dm_db_missing_index_group_stats s ON s.group_handle = g.index_group_handle
       INNER JOIN sys.dm_db_missing_index_details d ON d.index_handle = g.index_handle
WHERE d.database_id = 19 -- disable where, get value from result for proper db, set then apply to where
ORDER BY
       [Total Cost] DESC;

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s