|
To return a list of columns and their data types for a table use the following query.
Replace 'MyTableName' with the name of the table you wish to query.
select ordinal_position as Field,column_name + ' '+data_type + case isnull(character_maximum_length,'') when '' then '' else '(' + cast (character_maximum_length AS varchar(8)) + ')' end + case is_nullable when 'YES' then ', null' else ', not null' end as Table_Columns from information_schema.columns where table_name = 'MyTableName' order by ordinal_position
Works with SQL 2005 and higher.
|
04 August 2009 IB
SQL Server
|
Back To List
Did this article answer your question |
 |
Yes |
 |
No |
|
Other items of interest in our knowledgebase
|