Rajanand Ilangovan
Rajanand Ilangovan

Rajanand Ilangovan

List of indexes on a table with column details in SQL Server

Rajanand Ilangovan's photo
Rajanand Ilangovan
·Sep 20, 2022·

1 min read

List out all the indexes defined on a table and column details.

USE test_db;  
GO

SELECT 
OBJECT_NAME(i.object_id) AS table_name
,i.type_desc AS index_type
,i.name AS index_name  
,COL_NAME(ic.object_id,ic.column_id) AS column_name
,ic.index_column_id  
,ic.key_ordinal  
,ic.is_included_column  
,i.is_primary_key
,is_unique
FROM sys.indexes AS i  
INNER JOIN sys.index_columns AS ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id  
WHERE i.object_id = OBJECT_ID('dbo.table_name');

Result: image.png

Impressum