Bunch's Blog

One day I'll have a catchy subtitle, one day
posts - 83, comments - 94, trackbacks - 0

My Links

News

Tag Cloud

Archives

Green

Listing SQL Columns

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:

Print | posted on Wednesday, May 19, 2010 8:39 AM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: