SQL Server Denali CTP1 has hit the streets! I’ve been lucky enough to have been playing with it for a couple of weeks (thank you to those responsible – you know who you are) and that means I can now start talking publicly about some of the cool stuff I’ve learnt about this next version of SQL Server. In this blog post I’m quickly going to cover two new productivity enhancements in SQL Server Management Studio (SSMS):
- Surround With
- Insert Snippet
They’re very similar to each other so it makes sense to cover them both together.
First “Surround With”. This feature enables you to edit some existing code to wrap it with the scaffolding for common coding constructs like BEGIN…END, IF () BEGIN…END and WHILE () BEGIN…END. A picture speaks a thousand words so rather than tell you I’ll just show you instead.
Take the following code snippet:
Its a perfectly valid stored procedure definition although I happen to be one of those guys who likes to have BEGIN and END statements marking out the stored procedure body – Surround With can help me with that.
First I select the code that I want to “surround”:
Right-click and select “Surround With” (note that there is a keyboard shortcut too):
That brings up the surround with submenu where I browse to the option that I want, in this case its “BEGIN…END”
Hit Enter and voila…I’ve surrounded my code with a BEGIN…END block:
That’s it! A small new feature but a pretty useful one I hope you’ll agree. BEGIN…END is a fairly noddy use case but it gets more useful for the slightly more verbose IF() and WHILE() constructs.
This is probably the more useful of the two features I’m talking about here. “Insert Snippet” is similar to “Surround With” though I suspect you’ll be using it a lot more, in short what it does is create the skeleton DDL code for a new database object. All you need to do is right-click in a query window (or hit the keyboard shortcut CTRL+K, CTRKLX) and you’re presented with a list of code templates for various object types.
All you need to do is browse to the one you want, hit Enter, and you’re straight into the important business of development. Nice!
There is a Code Snippets Manager available for both Surround With and Insert Snippet that enables you to add your own snippets although not, as far I can see, edit the existing ones. I have an open Connect submission asking for that to be changed.
That’s it! Features such as these have been available in third party add-ins for a while but its nice to see them make their way into the core product. Enjoy!