How to select all the columns in the table - Need an optimised query

  • Can you please suggest various ways to select all column names in a table.

  • To do what exactly?

    If you just want a list of fields then SET FMTONLY ON before the query will give you what you need.

  • select top 0 * from <table name>




    My Blog: http://dineshasanka.spaces.live.com/

  • Select * from dbo.TableName where 1 = 0

  • Not recommended but another approach

    SELECT SO.[name], SC.colorder, SC.[name]

      FROM (SELECT [id], [name] FROM sysobjects WHERE xtype = 'U') SO

        INNER JOIN syscolumns SC ON SO.[id] = SC.[id]

    WHERE SO.[name] = 'YourTableNameHere'

    ORDER BY SO.[name], SC.colorder



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Thanks Guys!!!!!!!!!!!

  • You could use this query:

    select name, colorder from syscolumns where object_name(id) = 'yourtablename'

Viewing 7 posts - 1 through 6 (of 6 total)

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