SQL Swiss Army Knife #12 - Index information galore!

Blog do Ezequiel
Portuguese PFE SQL Server Team

Latest Updates
10/05/2014 - Latest update on the AdaptiveIndexDefrag procedure v1.5.8. Look for it in the "Ezequiel shortcuts" section on the right or just click HERE.

10/05/2014 - Updates to Maintenance plan deployment scripts available HERE

04/06/2014 - The SQL Swiss Army Knife Series Index

SQL Swiss Army Knife #12 - Index information galore!

Rate This
  • Comments 3

EDIT (06/06/2012): Added script for all databases (may cause performance problems in large servers) and current database only. also fixed issue with partition aligned indexes.

EDIT (19/11/2012): Added Heap information and redesigned duplicate and redundant index search.

EDIT (18/12/2012): Fixed miscellaneous issues and added schema information.

EDIT (20/01/2013): Added index related information.

EDIT (27/02/2013): Fixed issue with partition info; Removed alternate keys from search for Unused and Rarely used indexes.

EDIT (17/03/2013): Added more information to duplicate and redundant indexes output, valuable when deciding which to delete, namely if duplicates are non-clustered.

EDIT (19/03/2013): Fixed issue with potential duplicate index_ids in sys.dm_db_index_operational_stats relating to internal tables.

EDIT (06/05/2013): Changed data collection to minimize blocking potential on VLDBs.

EDIT (20/05/2013): Fixed issue with database names with special characters.

EDIT (04/06/2014): Refined search for duplicate and redundant indexes. 

Hello all,
Here is another post on SQL scripts that may help DBAs, following the series "SQL Swiss Army Knife". I’ve been using and tweaking this script for years now, and with a recent update for SQL 2012, I’ve decided to share it.
So, for the current database in scope, it will report a great deal of useful information about all indexes, including duplicate, redundant, rarely used and completely unused indexes.
After collecting the relevant information on the current database, the first report is “All_Index_Info” and "All_Heaps_Info", including name, index type, fragmentation and usage statistics, the ratio of reads vs. writes, amongst other information:


 “Unused Indexes” and “Rarely Used Indexes” are next, where unused are either indexes never touched since SQL Server started up, or indexes that were only updated, and never had seeks, scans or lookups. “Duplicate Indexes” and “Redundant Indexes” follow, where duplicate share the same keys and included columns. Redundant, on the other hand, are indexes sharing the part of the same key and/or included columns, such as in the examples below:


While the above is output at once, the following can be used separately. These are the listings of all “Index Columns” and its properties, ”Index_Details" with key columns information, and all “Constraint_Details”, including data types, key and column order:

Hope you find it useful.

Download scripts here: view_IndexInformation.sql (for all DBs at once) and view_IndexInformation_CurrentDB.sql (for a DB in scope)

Until next time!

Disclaimer: I hope that the information on these pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Ezequiel. Further, Ezequiel shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

Social Media Sharing
Leave a Comment
  • Please add 4 and 6 and type the answer here:
  • Post
  • can you please add clip it button on your site so i can clip it?


  • I receive an error using  view_IndexInformation_CurrentDB.sql

    Column 'sys.indexes.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

  • Hello Derek, thanks for the input. I had actually fixed this before, but it seems I never uploaded the fixed version.

    All fixed now.


Page 1 of 1 (3 items)