Column names, data types, and lengths

,

I used to list from sysobjects to get this information, but found the INFORMATION_SCHEMA is a lot easier.

select 
TABLE_NAME,
ORDINAL_POSITION 'Col No',
substring(rtrim(COLUMN_NAME),1,25) 'Column Name',
substring(DATA_TYPE + case when DATA_TYPE like '%char%' then '(' + 
	rtrim(convert(char(3),CHARACTER_MAXIMUM_LENGTH)) + ')' else '' end,1,25) 'DataType'
from INFORMATION_SCHEMA.COLUMNS 
order by ORDINAL_POSITION

Rate

Share

Share

Rate