Listing SQL Columns
Posted
by Bunch
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Bunch
Published on Wed, 19 May 2010 06:39:22 GMT
Indexed on
2010/05/19
13:01 UTC
Read the original article
Hit count: 170
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).
© Geeks with Blogs or respective owner