Export (0) Print
Expand All
Expand Minimize

COL_NAME (Transact-SQL)

Updated: 17 July 2006

Returns the name of a column from a specified corresponding table identification number and column identification number.

Topic link icon Transact-SQL Syntax Conventions


COL_NAME ( table_id , column_id )

table_id

Is the identification number of the table that contains the column. table_id is of type int.

column_id

Is the identification number of the column. column_id parameter is of type int.

sysname

Returns NULL on error or if a caller does not have permission to view the object.

In SQL Server 2005, 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 COL_NAME may return NULL if the user does not have any permission on the object. For more information, see Metadata Visibility Configuration and Troubleshooting Metadata Visibility.

The table_id and column_id parameters together produce a column name string.

For more information about obtaining table and column identification numbers, see OBJECT_ID (Transact-SQL).

The following example returns the name of the first column in the Employee table of the AdventureWorks database.

USE AdventureWorks;
GO
SET NOCOUNT OFF;
GO
SELECT COL_NAME(OBJECT_ID('HumanResources.Employee'), 1) AS 'Column Name';
GO

Here is the result set.

Column Name        
------------ 
EmployeeID

(1 row(s) affected

Release History

17 July 2006

New content:
  • Added the "Exceptions" section.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft