COL_NAME (T-SQL)

Returns the name of a database column given the corresponding table identification number and column identification number.

Syntax

COL_NAME(table_id, column_id)

Arguments
table_id
Is the identification number of the table containing the database column. table_id is of type int.
column_id
Is the identification number of the column. column_id parameter is of type int.
Return Types

sysname

Remarks

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.

Examples

This example returns the name of each column in the authors table of the pubs database.


Note The table identification number was generated by executing OBJECT_ID.


USE pubs

SET NOCOUNT OFF

SELECT COL_NAME(117575457, ORDINAL_POSITION)

FROM INFORMATION_SCHEMA.COLUMNS

WHERE TABLE_NAME = 'authors'

  

Here is the result set:

column_name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

------------------------------------------------------------------------

au_id                                                                                                                                                                                                                                                           au_id                                                                                                                                                                                                                                                          

au_lname                                                                                                                                                                                                                                                        au_lname                                                                                                                                                                                                                                                       

au_fname                                                                                                                                                                                                                                                        au_fname                                                                                                                                                                                                                                                       

phone                                                                                                                                                                                                                                                           phone                                                                                                                                                                                                                                                          

address                                                                                                                                                                                                                                                         address                                                                                                                                                                                                                                                        

city                                                                                                                                                                                                                                                            city                                                                                                                                                                                                                                                           

state                                                                                                                                                                                                                                                           state                                                                                                                                                                                                                                                          

zip                                                                                                                                                                                                                                                             zip                                                                                                                                                                                                                                                            

contract                                                                                                                                                                                                                                                        contract                                                                                                                                                                                                                                                       

  

(9 row(s) affected)

  

See Also
Expressions Metadata Functions
sysobjects  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.