Tags: column, field, names, procedure, programming, return, sql, stored, t-sql, table, write

How do I get the field names for a given table?

On Programmer » SQL

2,192 words with 2 Comments; publish: Thu, 29 May 2008 04:35:00 GMT; (20062.01, « »)

I was asked to write a stored procedure that will return the column/field names for any given table in a DB. I'm still new to T-SQL and don't know how to do this without returning * from a table then getting the fields names. I'd be passing the table name as a parameter to the SP. What's the easiest way to go about this? Is there an SQL function I could use? I am using SQL Server 2000 and VB6 on an NT 4.0 box. The fields names have to get returned to a combo box. Any help is appreciated.

All Comments

Leave a comment...

  • 2 Comments
    • select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS

      where TABLE_NAME = 'TableName'

      Jeff Duncan

      MCDBA, MCSE+I

      "stanleyb" <anonymous.sql.todaysummary.com.discussions.microsoft.com> wrote in message

      news:6F14FD5C-9DD3-423C-85D0-031E45DB6FAC.sql.todaysummary.com.microsoft.com...

      > I was asked to write a stored procedure that will return the column/field

      names for any given table in a DB. I'm still new to T-SQL and don't know

      how to do this without returning * from a table then getting the fields

      names. I'd be passing the table name as a parameter to the SP. What's the

      easiest way to go about this? Is there an SQL function I could use? I am

      using SQL Server 2000 and VB6 on an NT 4.0 box. The fields names have to

      get returned to a combo box. Any help is appreciated.

      #1; Thu, 29 May 2008 04:36:00 GMT
    • http://www.aspfaq.com/2177

      --

      Aaron Bertrand

      SQL Server MVP

      http://www.aspfaq.com/

      "stanleyb" <anonymous.sql.todaysummary.com.discussions.microsoft.com> wrote in message

      news:6F14FD5C-9DD3-423C-85D0-031E45DB6FAC.sql.todaysummary.com.microsoft.com...

      > I was asked to write a stored procedure that will return the column/field

      names for any given table in a DB. I'm still new to T-SQL and don't know

      how to do this without returning * from a table then getting the fields

      names. I'd be passing the table name as a parameter to the SP. What's the

      easiest way to go about this? Is there an SQL function I could use? I am

      using SQL Server 2000 and VB6 on an NT 4.0 box. The fields names have to

      get returned to a combo box. Any help is appreciated.

      #2; Thu, 29 May 2008 04:37:00 GMT