Skip to content

Commit 1248f8b

Browse files
authored
Refresh COL_NAME article (UUF 479205) (#34926)
1 parent 83dfae8 commit 1248f8b

1 file changed

Lines changed: 58 additions & 46 deletions

File tree

docs/t-sql/functions/col-name-transact-sql.md

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ title: "COL_NAME (Transact-SQL)"
33
description: "COL_NAME (Transact-SQL)"
44
author: markingmyname
55
ms.author: maghan
6-
ms.date: "07/24/2017"
6+
ms.reviewer: randolphwest
7+
ms.date: 08/07/2025
78
ms.service: sql
89
ms.subservice: t-sql
910
ms.topic: reference
@@ -17,64 +18,75 @@ helpviewer_keywords:
1718
- "names [SQL Server], columns"
1819
dev_langs:
1920
- "TSQL"
20-
monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || >= sql-server-linux-2017 || = azuresqldb-mi-current"
21+
monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current"
2122
---
2223
# COL_NAME (Transact-SQL)
24+
2325
[!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)]
2426

2527
This function returns the name of a table column, based on the table identification number and column identification number values of that table column.
26-
28+
2729
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
28-
29-
## Syntax
30-
30+
31+
## Syntax
32+
3133
```syntaxsql
32-
COL_NAME ( table_id , column_id )
33-
```
34-
34+
COL_NAME ( table_id , column_id )
35+
```
36+
3537
## Arguments
36-
*table_id*
38+
39+
#### *table_id*
40+
3741
The identification number of the table containing that column. The *table_id* argument has an **int** data type.
38-
39-
*column_id*
42+
43+
#### *column_id*
44+
4045
The identification number of the column. The *column_id* argument has an **int** data type.
41-
46+
4247
## Return types
48+
4349
**sysname**
44-
45-
## Exceptions
46-
Returns NULL on error, or if a caller does not have the correct permission to view the object.
47-
48-
In [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], 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` might return NULL, if the user does not have correct permissions on the object. See [Metadata Visibility Configuration](../../relational-databases/security/metadata-visibility-configuration.md) for more information.
49-
50-
## Remarks
50+
51+
## Exceptions
52+
53+
Returns `NULL` on error, or if a caller doesn't have the correct permission to view the object.
54+
55+
A user can only view the metadata of securables that the user owns, or on which the user is granted permission. This means that metadata-emitting, built-in functions such as `COL_NAME` might return `NULL`, if the user doesn't have correct permissions on the object. For more information, see [Metadata visibility configuration](../../relational-databases/security/metadata-visibility-configuration.md).
56+
57+
## Remarks
58+
5159
The *table_id* and *column_id* parameters together produce a column name string.
52-
53-
See [OBJECT_ID (Transact-SQL)](../../t-sql/functions/object-id-transact-sql.md) for more information about obtaining table and column identification numbers.
54-
55-
## Examples
56-
This example returns the name of the first column in a sample `Employee` table.
57-
60+
61+
For more information about obtaining table and column identification numbers, see [OBJECT_ID](object-id-transact-sql.md).
62+
63+
## Examples
64+
65+
[!INCLUDE [article-uses-adventureworks](../../includes/article-uses-adventureworks.md)]
66+
67+
### A. Return names of first two columns in a table
68+
69+
This example returns the name of the first two columns in the `Person.Person` table.
70+
5871
```sql
59-
-- Uses AdventureWorks
60-
61-
SELECT COL_NAME(OBJECT_ID('dbo.FactResellerSales'), 1) AS FirstColumnName,
62-
COL_NAME(OBJECT_ID('dbo.FactResellerSales'), 2) AS SecondColumnName;
63-
```
64-
65-
[!INCLUDE[ssResult](../../includes/ssresult-md.md)]
66-
72+
USE AdventureWorks2022;
73+
GO
74+
75+
SELECT COL_NAME(OBJECT_ID('Person.Person'), 1) AS FirstColumnName,
76+
COL_NAME(OBJECT_ID('Person.Person'), 2) AS SecondColumnName;
6777
```
68-
ColumnName
69-
------------
70-
BusinessEntityID
71-
```
72-
73-
## See also
74-
[Expressions (Transact-SQL)](../../t-sql/language-elements/expressions-transact-sql.md)
75-
[Metadata Functions (Transact-SQL)](../../t-sql/functions/metadata-functions-transact-sql.md)
76-
[COLUMNPROPERTY (Transact-SQL)](../../t-sql/functions/columnproperty-transact-sql.md)
77-
[COL_LENGTH (Transact-SQL)](../../t-sql/functions/col-length-transact-sql.md)
78-
79-
8078

79+
[!INCLUDE [ssResult](../../includes/ssresult-md.md)]
80+
81+
```output
82+
FirstColumnName SecondColumnName
83+
----------------- -----------------
84+
BusinessEntityID PersonType
85+
```
86+
87+
## Related content
88+
89+
- [Expressions (Transact-SQL)](../language-elements/expressions-transact-sql.md)
90+
- [Metadata Functions (Transact-SQL)](metadata-functions-transact-sql.md)
91+
- [COLUMNPROPERTY (Transact-SQL)](columnproperty-transact-sql.md)
92+
- [COL_LENGTH (Transact-SQL)](col-length-transact-sql.md)

0 commit comments

Comments
 (0)