Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 column in index

Author  Topic 

shubhada
Posting Yak Master

117 Posts

Posted - 2009-02-20 : 04:21:10
How to check any column is available in index or not on that table?

ex - table tbl1 having col1,col2,col3 ----

and have 2 indexes.

I want to check col2 is available in 2 indexes or not.




SQLTeam

jbp_j
Starting Member

24 Posts

Posted - 2009-02-20 : 04:54:37
hi,

try this one.

select object_name(id),name from sys.sysindexkeys as i
inner join sys.columns as c on i.colid = c.column_id and i.id = c.object_id
where object_name(id) = 'yourTableName'
and name = 'your Table Columnname'
Go to Top of Page

sridhar.dbe
Starting Member

34 Posts

Posted - 2009-02-20 : 05:03:36
select distinct object_name(c.object_id),c.name
from sys.index_columns as i
inner join sys.columns as c on c.object_id=i.object_id
and c.column_id=i.index_column_id
where
object_name(c.object_id)='table name'
c.name'column name

isk
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2009-02-20 : 05:39:45
sp_helpindex 'TableName'

Mike
"oh, that monkey is going to pay"
Go to Top of Page
   

- Advertisement -