Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Listing Tables and Indexes

By Uday,

Once in a while, a DBA or SQL developer is in the need of listing all the indexes of one or more tables in a given database.

Though the indexes can be viewed by using sp_help <table name> for a table, it does not help when it comes for multiple tables. Here the DBA's nice-to-have query is one to list Tables and Indexes.

Let's go and derive the query to list all the tables and their indexes.

For testing these queries in the test database, it is nice to have few tables created.
See the script for examples./

- sysobjects consists of all the objects in the database, while sysindexes has only index details.

Now, let's write the query in step by step fashion.

Query 1 - List all indexes in a database

Query 2 - Now let's exclude dtproperties table (indid = 255) and each tablename itself (indid =0) stored in sysindexes

Query 3 - List objects created by users

Query 4 - Let's build the complete query by joining both sysobjects and sysindexes.

Total article views: 3340 | Views in the last 30 days: 4
Related Articles

Noncluster at sysindexes

Noncluster at sysindexes


object_name(id) returning Null



Table not showing PK - PK is in sysindexes ?

Tables missing indexes but there seem to be entries for the indexes already in sysindexes ?



SQL2000, errors 8929,8928,8939,8965,8964 on SYSINDEXES


Indexes rebuilding problem

Indexes line present in sysindexes but not in sysobjects