Listing 1: Create a procedure to return all columns in a table's indexes, both key columns and included columns CREATE PROCEDURE get_index_columns(@object sysname, @index sysname = NULL) AS DECLARE @oid int SELECT @oid = object_id(@object) IF @index IS NULL SELECT @object AS [object_name], i.name AS [index_name], c.name AS [column], CASE ic.is_included_column WHEN 0 THEN 'KEY' ELSE 'INCLUDED' END AS [column usage] FROM sys.index_columns ic JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id JOIN sys.indexes i ON i.object_id = ic.object_id AND i.index_id = ic.index_id WHERE i.object_id = @oid AND i.index_id > 0 ELSE -- Index name was supplied. SELECT c.name as [column], CASE ic.is_included_column WHEN 0 then 'KEY' ELSE 'INCLUDED' END AS [column usage] FROM sys.index_columns ic JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id JOIN sys.indexes i ON i.object_id = ic.object_id AND i.index_id = ic.index_id WHERE i.object_id = @oid and i.name = @index AND i.index_id > 0