T-SQL Table Column Lookup Query

Dec 01, 2011 No Comments by

Here is a quick snippet of T-SQL that I use to find the column names in a given table in SQL Server:

SELECT
   ORDINAL_POSITION
  ,COLUMN_NAME
  ,DATA_TYPE
  ,CHARACTER_MAXIMUM_LENGTH
  ,IS_NULLABLE
  ,COLUMN_DEFAULT
FROM
  INFORMATION_SCHEMA.COLUMNS
WHERE
  TABLE_NAME = ‘table_name’
ORDER BY
  ORDINAL_POSITION ASC;

Just replace ‘table_name’ with the name of the table you want to get information about.  This is extremely useful especially when the list of columns is large and I need to access data on a field by field basis for transformation, comparison, etc…

Share this Post[?]
        
Uncategorized

About the author

The author didnt add any Information to his profile yet
No Responses to “T-SQL Table Column Lookup Query”

Leave a Reply