Monday, April 28, 2008

Get column info in MS SQL

Existing some ways how to get column information, but Joe Webb offered very simple and effective query:

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;

No comments: