How to get Table's field name as rows

  • Hi all,

    I have a table like

    T1

    ==================

    Name Address

    ==================

    abc xyz

    I need the result of select query as

    =========

    fields

    =========

    Name

    Address

    How can i do this. Please help.

    Thanks

    Nitin

  • select name from sys.columns where object_id = object_id('Tablename')

    "Keep Trying"

  • or

    Select column_name from information_schema.columns

    where table_name='your_table'


    Madhivanan

    Failing to plan is Planning to fail

  • Tables have fields???? 😀

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

  • I agree with the use of the information_schema instead of the system tables. There've been quite a few changes in how those system tables behave, what you can, etc., between 2000 & 2005/2008. The information_schema is pretty stable & standard between all the versions. A much better place to go.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply