Home > SQL Server > Get Index column name using Index_Col function – SQL Server

Get Index column name using Index_Col function – SQL Server


Index_Col() : This function returns the index column name for the given table name and index identification number. This function returns nvarchar(128) output value. We will get null if we don’t have permission to access the metadata of an object. It will also return null value if we retrieve the index column name for xml index column.

Function Syntax

INDEX_COL ( ‘[ database_name . [ schema_name ] .| schema_name ]
table_or_view_name’, index_id , key_id )

Example

USE AdventureWorks2012
select INDEX_COL(‘[Production].[Product]’, 1,1)

Output

pic1We can also use these catalog views to get all index and index column names.

select * from sys.indexes
select * from sys.index_columns

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: