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 RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

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

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