Get Column Names From Table in SQL Server

Using the below query you can easy to get column names from the Information schema in SQL server.

select COLUMN_NAME
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = N'YourTableName'

If you want result as comma , split

Select Stuff(
        (
        Select ', ' + C.COLUMN_NAME
        From INFORMATION_SCHEMA.COLUMNS As C
        Where C.TABLE_SCHEMA = T.TABLE_SCHEMA
            And C.TABLE_NAME = T.TABLE_NAME
        Order By C.ORDINAL_POSITION
        For Xml Path('')
        ), 1, 2, '') As Columns
From INFORMATION_SCHEMA.TABLES As T where T.TABLE_NAME='YourTableName'

Leave a Comment