SQL Server Management Studio has two different ways to do this.
Method 1: Ad-hoc
When the result is rendered you can right click on the resultset and click on Copy Header. This will copy the headers along with the resultset. Additionally, you can use the shortcut key CTRL+SHIFT+C for coping, column headers along with the result set.
Method 2: Option Setting at SSMS level
This is SSMS level settings and I kept this option always selected as I often need the column headers when I select the resultset.
Go Tools >> Options >> Query Results >> SQL Server >> Results to Grid >> Check the Box “Include column header when copying or saving the results.”
Both of the methods are discussed in following SQL in Sixty Seconds Video.
Here is the code used in the video.
Related Tips in SQL in Sixty Seconds:
- Copy Column Headers in Query Analyzers in Result Set
- Getting Columns Headers without Result Data – SET FMTONLY ON
If we like your idea we promise to share with you educational material.
Reference: Pinal Dave (https://blog.sqlauthority.com)