cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get a list of the column names of one particular table in SQL?

VolkerBarth
Contributor
22,256

Just a slight issue:

Something I frequently need: a comma-separated list of all column names ordered by column id (i.e. position) for one particular table, and I'm usually needing it while writing (ad-hoc) SQL code - so I'm not asking for a Sybase Central wizard approach:)

I'm using this frequently to build "SELECT col1 ... coln FROM MyTable ... " statements or the like.

Is there any builtin function - or anything better than the catalog query I'm about to post?

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

What I'm typically using is something like the following:

select list (column_name, ', ' order by column_id)
from systabcol key join systab
where table_name = 'MyTableName';

Works fine for v10 and above (and I'm posting it here to remind me of that tiny template), but I guess there are better builtin ways...

Answers (1)

Answers (1)

Former Member

I've used this approach before:

  1. select * from 'mytablename';
  2. highlight first row, right click and 'copy selected rows'
  3. paste results

You'll get two rows. Top row is column names. Bottom row is data. Delete data and you have a comma separated list of column names.