Get Column Names From Table in SQL

How to write a query to Get Column Names From Table in SQL Server is one of the standard Interview Questions you might face. For this Get Column Names From Table example, We are going to use the below shown data

Customer Table Data 0

The above screenshot will show you the data inside the NewCustomer table present in the database.

Get Column Names From Table in SQL Server Example 1

In this SQL example, we will show you how to Get Column names using INFORMATION_SCHEMA.

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'NewCustomers'
Get Column Names From Table in SQL Server 1

You can use the below query to get all the information about the Table

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'NewCustomers'
Get Column Names From Table in SQL Server 2

Get Column Names From Table Example 2

This Frequently asked Questions explains how to find the list of Column names in a Table using sys.columns.

SELECT name
FROM sys.columns 
WHERE OBJECT_ID = OBJECT_ID('NewCustomers')
Get Column Names From Table in SQL Server 3

Let me show you what will happen if we replace the name column with *

SELECT *
FROM sys.columns 
WHERE OBJECT_ID = OBJECT_ID('NewCustomers')
Get Column Names From Table in SQL Server 4