Wednesday 20 February 2013

Quick Byte: Select all column names in a table

Quick Byte: T-SQL query to select all the field/column names from a given table:

Select COLUMN_NAME -- or Select * for all column attributes (ie data_type, default_value, ...)
From INFORMATION_SCHEMA.COLUMNS
Where TABLE_NAME = 'TableName'
Order By ORDINAL_POSITION


Applies to SQL Server.