How To List All Indexed Columns In A Particular Table



TODO:

Have you ever wanted to list all indexed columns in a particular table?

 

SOLUTION:

 

select
    t.name, ind.name, col.name
from 
    sys.indexes ind
inner join 
    sys.index_columns ic on 
      ind.object_id = ic.object_id and ind.index_id = ic.index_id
inner join
    sys.columns col on
      ic.object_id = col.object_id and ic.column_id = col.column_id 
inner join
    sys.tables t on 
      ind.object_id = t.object_id
where 
    ind.is_primary_key = 0 
    and ind.is_unique = 0 
    and ind.is_unique_constraint = 0
    and t.is_ms_shipped = 0
    and t.name ='MyTable'
order by
    t.name, ind.name, col.name

 

NOTES:

There are no notes on this topic.