Home » Programming / Coding

Get Column Names of Table – Microsoft Sql

2 March 2011 1,377 views No Comment

This is how you can get the name of the columns from a table in MS SQL.

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = ‘TableName’

And if you want them as a comma separated list:

declare @list varchar(max)
select @list=COALESCE(@list+’, ‘,”)+COLUMN_NAME
FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = ‘TableName’
select @list
______________
From Webcosmo Webmaster Forum http://www.webcosmoforums.com/databases/27234-get-column-names-table-microsoft-sql.html

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.