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:

INTO #tmp
 SELECT DISTINCT T.[name] AS [table_name]
  ,I.[name] AS [index_name]
  ,AC.[name] AS [column_name]
 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