索引缺失与创建

 
 
 
 

  SELECT TOP 100
            [Total Cost] = ROUND(avg_total_user_cost * avg_user_impact
                                 * ( user_seeks + user_scans ), 0) ,
            user_seeks ,
            user_scans ,
            avg_total_user_cost ,
            avg_user_impact ,
            TableName = statement ,
            [EqualityUsage] = equality_columns ,
            [InequalityUsage] = inequality_columns ,
            [Include Cloumns] = included_columns ,
            'create index IX_' + PARSENAME(statement, 1) + '_'
            + REPLACE(REPLACE(REPLACE(equality_columns, '[', ''), ']', ''),
                      ',', '') + '  on ' + PARSENAME(statement, 1) + ' ('
            + REPLACE(REPLACE(REPLACE(equality_columns, '[', ''), ']', ''),
                      ',', '') + CASE WHEN included_columns IS  NULL THEN ''
                                      ELSE ') INCLUDE (' + included_columns
                                           + ')'
                                 END
  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     1 = 1
            AND statement LIKE '%SCT%'
  ORDER BY  [Total Cost] DESC

 
 

你可能感兴趣的:(索引)