Cry How to...

List all columns in a table


To list all the columns in a table the simplest way is:

exec sp_help <table-name>

unfortunately this returns more than just the columns in the table. Alternately, to just list the columns use:

select name from syscolumns where id=object_id('<table_name>')

where <table_name> is the name of the table. For example:

select name from syscolumns where id=object_id('Employees')


These notes have been tested against SQL Server 7.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.