Search This Blog

Wednesday 7 January 2015

Find the list of indexes in sql database.

Tip #5 Find List of Indexes in Sql Database.

I am posting some of the most useful queries which help a dba/ developer to optimize database performance. Please reference to different Tips in other blogs as well.

Following query will help in getting the list of all indexes in your database. Run the following query in your sql server query window:


SELECT *
INTO #tmp
FROM (
 SELECT DISTINCT T.[name] AS [table_name]
  ,I.[name] AS [index_name]
  ,AC.[name] AS [column_name]
  ,I.[type_desc]
  ,I.[is_unique]
  ,I.[data_space_id]
  ,I.[ignore_dup_key]
  ,I.[is_primary_key]
  ,I.[is_unique_constraint]
  ,I.[fill_factor]
  ,I.[is_padded]
  ,I.[is_disabled]
  ,I.[is_hypothetical]
  ,I.[allow_row_locks]
  ,I.[allow_page_locks]
  ,IC.[is_descending_key]
  ,IC.[is_included_column]
 FROM sys.[tables] AS T
 INNER JOIN sys.[indexes] I
  ON T.[object_id] = I.[object_id]
 INNER JOIN sys.[index_columns] IC
  ON I.[object_id] = IC.[object_id]
 INNER JOIN sys.[all_columns] AC
  ON T.[object_id] = AC.[object_id]
   AND IC.[column_id] = AC.[column_id]
 WHERE T.[is_ms_shipped] = 0
  AND I.[type_desc] <> 'HEAP'
 ) m
ORDER BY m.table_name
 ,m.index_name

SELECT * FROM #tmp

No comments:

Post a Comment

Enter your comments here...