• Great util!! One little improvement I made... I added this to the front of the SELECT (just before the first column) to make the create statements, that way you could just copy/paste the results of that into a new qry to run the create statements you want.

    'CREATE NONCLUSTERED INDEX IX1_' + object_name(sys.dm_db_missing_index_details.object_id)

    + left(cast(newid() as varchar(max)),5) + char(10) + 'on [dbo].'

    + object_name(sys.dm_db_missing_index_details.object_id) + ' (' +

    case

    when sys.dm_db_missing_index_details.equality_columns is not null

    and sys.dm_db_missing_index_details.inequality_columns is not null

    then sys.dm_db_missing_index_details.equality_columns

    + ',' + sys.dm_db_missing_index_details.inequality_columns

    when sys.dm_db_missing_index_details.equality_columns is not null

    and sys.dm_db_missing_index_details.inequality_columns is null

    then sys.dm_db_missing_index_details.equality_columns

    when sys.dm_db_missing_index_details.inequality_columns is not null

    then sys.dm_db_missing_index_details.inequality_columns

    end

    + ')' + char(10)

    +

    case

    when sys.dm_db_missing_index_details.included_columns is not null

    then 'Include (' + sys.dm_db_missing_index_details.included_columns + ')'

    else ''

    end as CreateIndexStmt

    --Vincent yovincent@hotmail.com

    EDIT:

    The missing index DMVs this qry is based on often report missing indexes that, if created, would have too many columns... Imagine the performance impact when you go to do an update or insert on a table with a 50 column index!! Therefore, I also added this to the end of the WHERE clause to keep the qry from returning results with a ton of included columns.

    AND isnull(Len(included_columns)-Len(Replace(included_columns,',',''))+1,1)<10

    --Vincent yovincent@hotmail.com