Tel. +44(0)208 4716864
info@softstuff-consulting.com
Follow us on Twitter  http://www.twitter.com/softstuffc
Softstuff Home Knowledgebase Home Contact Us Blog
GoldMine CRM SQL Server QuoteWerks Microsoft Excel Microsoft Word C# Windows XP Microsoft Dynamics CRM HEAT Sage CRM
A query to retrieve a list of Columns in a table

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

 



 

Search our knowledgebase

Look In   For  
Enter a word or phrase to search for. eg. shrink

Enter your Email Address to receive the latest knowledgebase items delivered direct to your inbox.

Subscribe to the knowledgebase in your favourite RSS reader:   Plain RSS 2.0 Feed   Add to Google  Add to My Yahoo!

Note:
Softstuff accepts no responsibility for the use of information contained within this item. No warranties are implied or provided and it is advised that you have a working knowledge of the technologies contained, and we will not be held liable for system downtime, or data loss caused, unless we have specifically advised in writing to you that this is the case during the course of a support issue raised and accepted by us.
 

Copyright Softstuff Consulting 2007-2009