How do you return the column names of a table?

Belliez picture Belliez · Mar 1, 2009 · Viewed 540.9k times · Source

How would I return the column names of a table using SQL Server 2008? i.e. a table contains these columns- id, name, address, country and I want to return these as data.

Answer

Gulzar Nazim picture Gulzar Nazim · Mar 1, 2009

Not sure if there is an easier way in 2008 version.

USE [Database Name]
SELECT COLUMN_NAME,* 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'YourTableName' AND TABLE_SCHEMA='YourSchemaName'