Sharing the Code

  • Comments 1

I’ve worked in several multi-developer/multi-DBA shops in my day, and I’ve also taught a few DBA courses here and there. If you’re in the same situation, you know that it’s often important to be able to show your code to others. I have two tips for SQL Server Management Studio (SSMS) that have been helpful to me that I thought I would share. They are fairly obvious, but as the saying goes, “It isn’t obvious if you’ve never seen it.”

 

The first tip is to turn on line numbers in the SSMS output of a query. This prints numbers next to each line in the output panel. To do that, open SSMS, and then click Tools and then Options. From there, expand the Text Editor and then click All Languages. You’ll see an option on the right to display Line numbers. This won’t take effect until you open another query window.

 

Another useful option, especially for training or for code reviews, is to include the query text itself with the output of a query run. Stay right in those same options, and expand the Query Results item. In either Results to Grid or Results to Text you’ll see an option to Include the query in the result set. Set that option and you’ll get the query right at the top of the results. I normally do this in text mode, and the neat thing about it is that the query is wrapped in a block comment – meaning that if the students grab the results they won’t accidentally run the query again unless they want to.

Leave a Comment
  • Please add 3 and 5 and type the answer here:
  • Post
  • I’ve worked in several multi-developer/multi-DBA shops in my day, and I’ve also taught a few DBA courses

Page 1 of 1 (1 items)