Jimmy May's Blog

SQL Server Performance, Best Practices, & Productivity

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

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

  • Comments 8

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
http://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

Leave a Comment
  • Please add 2 and 7 and type the answer here:
  • Post
  • Jimmy, I am huge fan of simple but practical tips like the one you share here.

    Very useful - thanks for sharing!

  • @alikl:  You're welcome.  Here are some of the other defaults I change in the SSMS Options dialog:

    Line numbers: Text Editor > Plan Text > General

    Tab behavior: Text Editor > Plan Text > Tabs

    Keyboard shortcuts for SProcs: Environment > Keyboard

    The later is a *huge* productivity enhancement.  I'll blog about it sometime.

  • 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.

  • 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

  • Having the column headers included with the copied results is very helpful, but my version of SQL defaults to not including them, and my brain defaults to forgetting to reset the option.  Can saving the col. headers be set as the Query Options default?  thanks, Roger

  • Roger, I'm not sure what you're asking here.  That's the whole point of my post, to configure it as a default option for SSMS. ;-)  Please clarify.

  • 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?

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

Page 1 of 1 (8 items)