How to list all columns of a given sql query

2019-07-07 05:27发布

is there an easy way to get a list of all columns of a SQL query? They are listed in the header of the results window of SSMS but I can't copy them.

Thanks in advance.

EDIT:

sorry, I found it myself after a little googling:

http://vidmar.net/weblog/archive/2008/06/05/save-sql-query-results-with-column-names-in-msssms.aspx

3条回答
▲ chillily
2楼-- · 2019-07-07 05:54

If you change to Results To Text, then you can copy them.

To save actually executing the full query just to get the column names, you could also do:

SET FMTONLY ON;
SELECT * FROM SomeTable;

This will just return the metadata about the columns the query returns. Saves waiting around if the query is meaty.

查看更多
够拽才男人
3楼-- · 2019-07-07 05:55

Change the result window to 'Results to text' instead of 'Results to grid'.

This can be done by clicking of the on of the Icons above the query window. It looks somewhat like a notepad icon.

查看更多
聊天终结者
4楼-- · 2019-07-07 06:07

Go to Query -> Query Options and check the following box alt text

查看更多
登录 后发表回答