Find all Indexes that have Included Columns in SQL Server Database

To find all indexes in all user tables in a SQL Server database that have included columns, you can use this query:

SELECT DB_NAME() AS Database_Name
, AS Schema_Name
, AS Table_Name
, o.type_desc AS 'Table_Type'
, AS Index_Name
, AS 'Included_Column_Name'
, i.type_desc AS Index_Type
FROM sys.indexes i
INNER JOIN sys.objects o ON i.object_id = o.object_id
INNER JOIN sys.schemas sc ON o.schema_id = sc.schema_id
INNER JOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id
INNER JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id
WHERE ic.is_included_column = 1 AND o.type = 'U'
ORDER BY Table_Name

We can see that for example index IX_ProductId_TransactionDate in dbo.bigTransactionHistory has two included columns: Quantity and ActualCost:

If the post helped you, please share it:
Pin It

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">