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 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

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'
Using INFORMATION_SCHEMA 2

Get Column Names From Table Example 2

This Frequently Asked Question 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')
Select OBJECT_ID from sys.columns 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')
SELECT * FROM sys.columns
Categories SQL