Is there a way to expand the column list in a SELECT * from #Temp_Table in SSMS?

11,223

Solution 1

You can just drag the column's subfolder from the object explorer into the editor and the columns will be added as a list.

Solution 2

Very similar to this question. Here is the accepted answer from that question:

select * from tempdb.sys.columns where object_id =
object_id('tempdb..#mytemptable');
Share:
11,223
Daniel E.
Author by

Daniel E.

Updated on June 05, 2022

Comments

  • Daniel E.
    Daniel E. almost 2 years

    As seen here LINK you can hover over the * in a SELECT * from... and a tooltip will come up with a list of the columns represented by that *.

    Is there a way to copy the text from the tooltip to the clipboard?

    I know that you can use the columns folder in the object explorer to generate a list of columns by dragging it into the query editor window, but this cannot work for temp tables as they do not appear in the object explorer.

    EDIT

    For completeness sake, the answer below "You can right-click on the table in Object Explorer and select Script Table as->CREATE to->New Query Editor Window." is also not workable for the same reason as above.

    END EDIT

    I do not see a way to do this in SSMSBoost, which is an add-on for SSMS that I use. (The only reason I mention it is I am pretty sure I have seen the SSMSBoost developers on SO, feature request??)

    EDIT 2: Is there any other way to quickly expand the * in a SELECT * from #Temp_Table without actually running the code to create the temp table? END EDIT 2

  • Damien_The_Unbeliever
    Damien_The_Unbeliever over 10 years
    Not doable on temp tables, which the OP has indicated they're interested in.
  • Daniel E.
    Daniel E. over 10 years
    It is similar, however this requires the code to be run and the table actually created, that tooltip populates using Intellisense (I assume) and does not require the table to actually exist. I would like to know if there is a way to do it on the fly...
  • wergeld
    wergeld over 10 years
    Interesting. I see what you mean. I mad a script with both a temp table and a table variable but did not "create" them. Hovering over the * showed the column names/types/sizes.
  • Daniel E.
    Daniel E. over 7 years
    Not doable on temp tables, which is very specifically what the question is about.
  • Scotch
    Scotch about 3 years
    Did not answer the question at all. There is no folder to drag for CTE and temp tables.
  • Daniel E.
    Daniel E. over 2 years
    The object '[#tmp]' does not exist in database 'Test' or is invalid for this operation. This still doesnt work on temp tables.