How to list all columns of a given sql query

让人想犯罪 __ 提交于 2019-12-23 16:52:16

问题


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


回答1:


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




回答2:


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:


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.



来源:https://stackoverflow.com/questions/3777046/how-to-list-all-columns-of-a-given-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!