Wednesday, March 7, 2012

list of columns in a table

Hi All,

I have a simple question, I want to get a list of all columns in a given table. result shouldn't give me rows. so even if table is huge the query runs quickly. what's the code for this

thanks

sonny

One way is something like:

Code Snippet

select c.colid,

c.name

from sysobjects o,

syscolumns c

where o.id = c.id

and o.name = 'nameOfYourTable'

order by c.name

|||

Another way is:

select Column_Name from INFORMATION_SCHEMA.Columns where Table_Name='Tablename'

|||

Hi kent,

that worked. Thanks.

Sonny

|||

Hi Mobin,

This is improvement sinc the columns are sorted as well.

thanks

sonny

No comments:

Post a Comment