共用方式為


How to: Copy “Column Header” in SQL 2008 SSMS, SQL 2005 SSMS and SQL 2000 Enterprise Manager

SQL Server Management Studio 2008

SQL Server Management Studio 2008 (SSMS) has never failed to surprise me with it’s little (yet useful) enhancements. Here’s adding to the list:

As a common need, you are required to Save/Copy SSMS query output to other files (E.g. Excel). This however had a limitation that you could NOT copy the ‘Column Headers’.

In SQL Server Management Studio 2008, you can actually Copy “Column Headers” from query results window. Here’s how:

1. In SSMS, Result window. Right-Click on column name

2. Select Copy with Header option (refer below screen)

copy_with_header

What’s more, you can manage SQL 2005 database from SQL 2008 Management Studio and get benefits of SSMS enhancements, like one above.

SQL Server Management Studio 2005

For SQL Server 2005 SSMS, follow below steps:

1.  SSMS Tools –> Options –> Query Results –> SQL Server –> Result to Grid

2. Check –> “Include column headers when copying or saving to result

image

SQL Server 2000 Enterprise Manager

For SQL Server 2000 Enterprise Manager, follow below steps:

1. Enterprise Manager –> Tools –> SQL Server Query Analyzer –>  Tools –>  Options –>  Results

2. Default results Target : “Results to Text”

3. Results output format : “Tab Delimited”

4. Print column headers : Checkbox ON(check)

image

Try, You Got to Enjoy It !

Disclaimer: I work at Microsoft. Everything here, though, is my personal opinion and is not read or approved by Microsoft before it is posted. No warranties or other guarantees will be offered as to the quality of the opinions or anything else offered here.

Comments

  • Anonymous
    April 10, 2009
    PingBack from http://asp-net-hosting.simplynetdev.com/how-to-copy-%e2%80%9ccolumn-header%e2%80%9d-in-sql-management-studio-2008/

  • Anonymous
    June 13, 2009
    In SQL2005 you can copy the column headings but you have to turn it on - Tools/Options/Query Results/SQL Server/Results To Grid and check 'Include column headers when copying or saving the results' Regards Paul

  • Anonymous
    August 04, 2009
    -- Paul I have enabled that but it didn't worked in my case. can please tell me exact steps to do that Thanks, AM

  • Anonymous
    August 09, 2009
    Thanks Varund! (and thanks Paul)

  • Anonymous
    February 04, 2010
    how would you do the same in sql 2000....

  • Anonymous
    February 04, 2010
    The steps are lil different here: SQL Server Query Analyzer --> Tools --> Options --> Results Default results Target : Results to Text Results output format : Tab Delimited Print column headers : Checkbox ON(check) Now you will be able to view and copy column header from query output results. Hope this will help! Varun

  • Anonymous
    May 11, 2010
    There is a property "Include column headers when copying or saving the results" in Options/Query Results/SQL Server/Results to Grid, but in my experience it does NOT work (no effect). If you copy the result set from the grid in "Edit * Rows" table PopUp Menu, you can't get headers. You have to use a query or "Select Top * Rows" table PopUp menu which effectively opens a new query. Here you can select one, several or all rows and use "Copy with Headers" PopUp Menu to get headers with the selected rows to paste to Excel.

  • Anonymous
    May 24, 2010
    Hello Jani, Thanks for your feedback, It seems you are using the "Open table in grid" option which will not have the feature to copy headers. I want you to refer below steps: SQL Server Query Analyzer --> Tools --> Options --> Results Default results Target : Results to Text Results output format : Tab Delimited Print column headers : Checkbox ON(check) Now you will be able to view and copy column header from query output results. Hope this will help! Varun