Wednesday, November 4, 2009

Displaying the List of Column Names in SQL Server

Two ways to display the list of column names for a table. The examples use the AdventureWorks database.

  1. Use the sp_help procedure.
    exec sp_help 'HumanResources.Employee'
  2. Query the information_schema table.

SELECT column_name
FROM information_schema.columns
WHERE table_name = 'HumanResources.Employee'
ORDER BY ordinal_position