Solved

Index Details Of a Table in SQL Server

Posted on 2004-09-10
2
6,858 Views
Last Modified: 2008-01-09
If i want to see the Index deatils for a given table say 'ABC' how can i do it? I need

INDEX_NAME, COLUMN_NAME, TABLE_NAME, INDEX_TYPE columns for
       In oracle i am able to find it out from the query mentioned below,
   select B.INDEX_NAME, B.COLUMN_NAME, B.TABLE_NAME, A.INDEX_TYPE from USER_INDEXES A,

USER_IND_COLUMNS B
where B.TABLE_NAME = 'ABC' AND A.INDEX_NAME = B.INDEX_NAME
order by 3;


Please tell me how to do it in SQL Server? My mail ID is, kama_biet@rediffmail.com


Regards...
Sujit
0
Comment
Question by:sujit_kumar
2 Comments
 
LVL 10

Accepted Solution

by:
AustinSeven earned 50 total points
ID: 12025807
sp_helpindex 'tablename'

AustinSeven
0
 
LVL 11

Author Comment

by:sujit_kumar
ID: 12065068
Here is the answer,

SELECT  CAST(SO.[name] AS CHAR(20)) AS TableName
      , CAST(SI.[name] AS CHAR(30)) AS IndexName
      , CAST(SC.[name] AS CHAR(15)) AS ColName
      , CAST(ST.[name] AS CHAR(10)) AS TypeVal
      , CASE WHEN (SI.status & 16)<>0 THEN 'Yes' ELSE 'No' END AS ClusteredIndex
FROM
      SYSOBJECTS SO INNER JOIN SYSINDEXES SI INNER JOIN SYSINDEXKEYS SIK
      ON SIK.[id] = SI.[id]
      AND SIK.indid = SI.indid INNER JOIN SYSCOLUMNS SC INNER JOIN SYSTYPES ST
    ON SC.xtype = ST.xtype ON SIK.[id] = SC.[id]
      AND SIK.colid = SC.colid
      ON SO.[id] = SI.[id]
WHERE SO.xtype = 'u'
AND SI.indid > 0
AND      SI.indid < 255
AND      (SI.status & 64)=0
ORDER BY
      TableName
      , IndexName
      , SIK.keyno

Regards....
Sujit
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now