索引缺失与创建

 
 
 
 

  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

 
 

posted @ 2012-04-09 14:36  qanholas  阅读(687)  评论(0编辑  收藏  举报