Events
Sep 15, 6 AM - Sep 17, 3 PM
The best SQL community-led learning event. Sept 2025. Save €200 with code FABLEARN.
Get registeredThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Returns the indexed column name. Returns NULL for XML indexes.
Transact-SQL syntax conventions
INDEX_COL ( '[ database_name . [ schema_name ] .| schema_name ]
table_or_view_name', index_id , key_id )
database_name
Is the name of the database.
schema_name
Is the name of the schema to which the index belongs.
table_or_view_name
Is the name of the table or indexed view. table_or_view_name must be delimited by single quotation marks and can be fully qualified by database name and schema name.
index_id
Is the ID of the index. index_ID is int.
key_id
Is the index key column position. key_ID is int.
nvarchar (128 )
Returns NULL on error or if a caller does not have permission to view the object.
A user can only view the metadata of securables that the user owns or on which the user has been granted permission. This means that metadata-emitting, built-in functions such as INDEX_COL may return NULL if the user does not have any permission on the object. For more information, see Metadata Visibility Configuration.
The following example returns the column names of the two key columns in the index PK_SalesOrderDetail_SalesOrderID_LineNumber
.
USE AdventureWorks2022;
GO
SELECT
INDEX_COL (N'AdventureWorks2022.Sales.SalesOrderDetail', 1,1) AS
[Index Column 1],
INDEX_COL (N'AdventureWorks2022.Sales.SalesOrderDetail', 1,2) AS
[Index Column 2]
;
GO
Here is the result set:
Index Column 1 Index Column 2
-----------------------------------------------
SalesOrderID SalesOrderDetailID
Expressions (Transact-SQL)
Metadata Functions (Transact-SQL)
sys.indexes (Transact-SQL)
sys.index_columns (Transact-SQL)
Events
Sep 15, 6 AM - Sep 17, 3 PM
The best SQL community-led learning event. Sept 2025. Save €200 with code FABLEARN.
Get registeredAsk Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in