SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Listing Tables and Indexes

By Uday, 2007/12/17

Total article views: 1017 | Views in the last 30 days: 41

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.

By Uday, 2007/12/17

Total article views: 1017 | Views in the last 30 days: 41
Your response
 
 
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com