Поделиться через


SSMS Query Results: “Include column headers when copying or saving the results"

In my work with external customers, I collaborate with some excellent DBAs & Architects.  But I've noticed many of them are not aware that you can capture column headers from query results to grid in SSMS.

When a very bright engineer I work with—not a SQL SME yet one of the smartest guys I know—told me he didn't know about it either, I decided to document the simple protocol.  I'm not the first person to post this topic, but I wouldn't need to do so if everyone already knew about it.

There are two ways to get the column headers from SSMS into, say, Excel.

The Hard Way 

You can simply type out the column names by hand.

The Right Way

Make it the SSMS default:

  • Open SSMS
  • Click Tools > Options
  • In the Options dialog, expand Query Results > SQL Server > Results to Grid, then check “Include column headers when copying or saving the results”
  • Click OK
  • Close & restart SSMS

image 

As my friend the cellist says, "Viola! "

The steps are the same for SQL Server 2005 & 2008.

Additional Resources

Explore these topics for additional information on SSMS options & increase your SSMS productivity.

Administrivia

Jimmy May , MCDBA, MCSE, MCITP: DBA + DB Dev | Senior Performance Consultant: SQL Server
A.C.E.: Assessment Consulting & Engineering Services
https://blogs.msdn.com/jimmymay
Oh, the weather outside is frightful, but SQL Server is delightful! —Brian Moran

This post was written with the PracticeThis.com plugin for Windows Live Writer

Comments

  • Anonymous
    February 23, 2009
    The comment has been removed

  • Anonymous
    February 23, 2009
    The comment has been removed

  • Anonymous
    February 24, 2009
    In SSMS 2008 you can also right click on the results grid and choose "Copy with Headers". No options changes are required for it to work.

  • Anonymous
    March 16, 2009
    Thanks for this very useful tip.  I was using DBArtisan just because it copies the col headers, but with this setting I can stay with SQL Serv. Best Regards, Chris

  • Anonymous
    March 12, 2010
    The comment has been removed

  • Anonymous
    March 12, 2010
    The comment has been removed

  • Anonymous
    October 18, 2010
    Many thanks, I have been having this problem for ages and had been either typing them or setting it manully each time with a right click, NB surely this should have been the factory default?

  • Anonymous
    August 16, 2012
    Thanks for the tip. It was not clear that you have to restart SSMS for this to take effect. (Using SSMS 2012)