Quick SSMS Tip

It is widely known that I am a horrible speller and hate to type code. I tend to use a lot of code snippets and reuse code to avoid writing it. So, when I find little tips that make coding easier for me, I like to share.

Did you know that you can surround your code with a click of a button with IF, BEGIN END, WHILE code blocks? SQL Server Management Studio (SSMS) gives us the basic structure of a Transact-SQL statement code block as a starting point.

Take Look In SSMS

In a query window, Right Click and Choose Surround With (note the hot keys of Ctrl+K or Ctrl+S)

It will bring up a code “window” where you can choose which code block you want to add.

Here is what you get when you choose each one.

I am not sure if this has always been here or it’s a recent add that I just stumbled on to. Regardless,  this feature along with the full list of code snippets, as well as some custom ones I’ve utilized over the years definitely come in handy. You can find more on code snippets inside management studio here.

About Monica Rathbun

Monica Rathbun lives in Virginia, is a Microsoft MVP for Data Platform and Microsoft Certified Solutions Expert. She has nearly two decades of experience working with a wide variety of database platforms with a focus on SQL Server and the Microsoft Data Platform. She is a frequent speaker at IT industry conferences on topics including performance tuning and configuration management. She is the Leader of the Hampton Roads SQL Server User Group. She is passionate about SQL Server and the SQL Server community, doing anything she can to give back. Monica can always be found on Twitter (@sqlespresso) handing out helpful tips. You can find Monica blogging at sqlespresso.com 
Bookmark the permalink.

One Comment

  1. Nifty. I’m going to have to try to remember this and make it part of my toolkit!

Comments are closed