Geeks With Blogs
Bunch's Blog One day I'll have a catchy subtitle, one day

When I am writing up stored procedures in SSMS sometimes I need to know what column types are used in a table. For instance I will know the table name but I might not remember exactly the length of a varchar column or if a column stored the data as an integer or varchar. And I may not want to scroll through all the tables in Object Explorer to find the one I want. A lot of times it is easier if I can just write a quick query to pull up the information I need. The syntax to do something like this is pretty easy.

SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM
yourdbname.information_schema.columns
WHERE TABLE_NAME = ‘yourtablename’

After running that you will get a listing in the Results pane just like any other query with the column name, data type and length (if any).

Technorati Tags:
Posted on Wednesday, May 19, 2010 8:39 AM | Back to top


Comments on this post: Listing SQL Columns

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Bunch | Powered by: GeeksWithBlogs.net