Joe Webb

Musing and observations about SQL Server, other technogies, and sometimes just life in general
posts - 64, comments - 148, trackbacks - 0

My Links

SQLTeam.com Links

News

Add to Technorati Favorites

Search this Blog
 




Archives

Post Categories

About me

Sunday, April 27, 2008

Getting column information using T-SQL

 

Ocassionally, I see a question in the MSDN Forums where someone wants to know how to retrieve a list of column information for a table using only T-SQL.

Although there are several ways in which to approach this, I like the following method.

SELECT 
ORDINAL_POSITION
,COLUMN_NAME
,DATA_TYPE
,CHARACTER_MAXIMUM_LENGTH
,IS_NULLABLE
,COLUMN_DEFAULT
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE

TABLE_NAME = 'Product'
ORDER BY
ORDINAL_POSITION ASC;

Do you have a different way of doing this that you'd like to share? If so, feel free to leave a comment, sharing your way and why you like it.

Cheers!

Joe


kick it on DotNetKicks.com

posted @ Sunday, April 27, 2008 9:05 AM | Feedback (9)

Powered by: