In this article I will explain with an example, how to get Column names from a database table in SQL Server.
This article will discuss two methods to get Column names from a database table:
1. Using SQL Query
 
 

Database

Here I am making use of Microsoft’s Northwind Database. You can download it from here.
 
 

Fetching Column Names of Table using SQL Query

The INFORMATION_SCHEMA.COLUMNS table returns information about all columns within a database. A SELECT statement needs to be executed over the table and the Table Name whose Column names needs to be fetched is displayed in WHERE clause.

Syntax

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Your Table Name'
ORDER BY ORDINAL_POSITION
 

Example

In the following example, the Column names of Employees table of Northwind database are fetched.
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Employees'
ORDER BY ORDINAL_POSITION
 

Screenshot

Tip Query to get all column names from database table in SQL Server
 
 

Fetching Column Names of Table using Stored Procedure

The System Stored Procedure sp_columns returns Column names with additional information from the database table in SQL Server.

Syntax

EXEC sp_columns 'Your Table Name'
 

Example

In the following example, the Column names of Employees table of Northwind database are fetched using the Stored Procedure sp_columns.
EXEC sp_columns 'Employees'
 

Screenshot

Tip Query to get all column names from database table in SQL Server