Copy Column Headers in SSMS grid result

For sometime now, we get daily requests from one of the application team to check why the CPU is spiking. That spike is very momentary. The concern is that whenever the CPU spikes they get an alert, which they forward to us invariably.

It is an instance running SQL Server 2005 and one of my colleagues was telling me how annoying it was to copy the column headers in SSMS 2005.  This discussion came in because I was given a snapshot of the queries running on that instance when the CPU spiked. I found it difficult to analyze because there were no headers in the spreadsheet. This reminded me of a scenario when one of the DBAs gave me the output of sys.dm_db_index_physical_stats which had 22 columns and no column headers!

By default when the content of the result in Grid view is copied, the column headers are not copied. There is an option in SSMS to Include column headers when copying or saving the results. This option is under Tools –> Options in SSMS.

After this option is selected, whenever the results in SSMS Grid View are copied, the column headers are also included. Very useful when copying results with a lot of columns to spreadsheets for later analysis.

SSMS in SQL Server 2008 is a step ahead regarding this. On right clicking on the result set in SSMS, Copy with Headers option is available which will do exactly what is says.