Wednesday, January 7, 2009

Getting table index information in SQL Server

At some time today, I had to compare the indices of various database tables.
To this end, I needed a fast way of getting index information for specific tables.

In SQL Server, there is a system stored procedure (hosted in the master database) called sp_helpindex.

The syntax for using it is the following:

EXEC sp_helpindex 'schema.table_name'

The execution of the stored procedure will return the following information for all the indices in the given table:

  • index name
  • index description (clustered, nonclustered, etc.)
  • index keys
Applies to SQL Server 2000, 2005 and 2008.
Check out my latest eBooks on SQL Server:
Administering SQL Server - Ebook Tuning SQL Server - Ebook

Easily secure your SQL Server instances! Try out DBA Security Advisor!
DBA Security Advisor for SQL Server by SQLArtBits
DBA Security Advisor was developed by SQLArtBits. The tool was being carefully developed for an entire year and it contains comprehensive security checks and recommendations based on proven SQL Server security best practices. Feel free to download and use the Community Edition which is free and if you find it useful, you can consider upgrading to the Enterprise Edition!

Artemakis Artemiou [MVP]

Author & Editor

Artemakis Artemiou is a Senior SQL Server Architect, Software Developer and Microsoft Data Platform MVP. He is also an author, regular blogger, president of Cyprus.NET User Group and CY Country leader of INETA-EU. He is also the creator of DBA Security Advisor and In-Memory OLTP Simulator. Artemakis is a frequent guest author of worldwide well-respected online journals where he writes articles focusing on many SQL Server topics.

Reference: The SQL Server and .NET Hub (