Wednesday, December 10, 2008

Select column names in SQL Server

The following query will give you the the columns of an specific table in SQL Server. This is useful sometimes when you need the names.

select column_name, data_type, character_maximum_length from information_schema.columnswhere table_name = 'table_name'

If you need the names in an excel row, I will recommend the following:
  1. Perform the query above
  2. Copy the column with the names in a textpad
  3. Replace character \n with ,
  4. Save the file with extension .csv
  5. Open the .csv file with Excel
  6. Copy and paste the headers (which should be each name in each cell) to wherever you need them

No comments: