Advertisement
kavallo

Ver Indices Faltantes en Sql Server

Jul 8th, 2015
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1.  
  2. -- Original Author: Pinal Dave (C) 2011
  3. SELECT
  4. dm_mid.database_id AS DatabaseID,
  5. dm_migs.avg_user_impact*(dm_migs.user_seeks+dm_migs.user_scans) Avg_Estimated_Impact,
  6. dm_migs.last_user_seek AS Last_User_Seek,
  7. OBJECT_NAME(dm_mid.OBJECT_ID,dm_mid.database_id) AS [TableName],
  8. 'CREATE INDEX [IX_' + OBJECT_NAME(dm_mid.OBJECT_ID,dm_mid.database_id) + '_'
  9. + REPLACE(REPLACE(REPLACE(ISNULL(dm_mid.equality_columns,''),', ','_'),'[',''),']','') +
  10. CASE
  11. WHEN dm_mid.equality_columns IS NOT NULL AND dm_mid.inequality_columns IS NOT NULL THEN '_'
  12. ELSE ''
  13. END
  14. + REPLACE(REPLACE(REPLACE(ISNULL(dm_mid.inequality_columns,''),', ','_'),'[',''),']','')
  15. + ']'
  16. + ' ON ' + dm_mid.statement
  17. + ' (' + ISNULL (dm_mid.equality_columns,'')
  18. + CASE WHEN dm_mid.equality_columns IS NOT NULL AND dm_mid.inequality_columns IS NOT NULL THEN ',' ELSE
  19. '' END
  20. + ISNULL (dm_mid.inequality_columns, '')
  21. + ')'
  22. + ISNULL (' INCLUDE (' + dm_mid.included_columns + ')', '') AS Create_Statement
  23. FROM sys.dm_db_missing_index_groups dm_mig
  24. INNER JOIN sys.dm_db_missing_index_group_stats dm_migs
  25. ON dm_migs.group_handle = dm_mig.index_group_handle
  26. INNER JOIN sys.dm_db_missing_index_details dm_mid
  27. ON dm_mig.index_handle = dm_mid.index_handle
  28. WHERE dm_mid.database_ID = DB_ID()
  29. ORDER BY 4
  30. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement