Shortcut: Using Templates in SQL Server Management Studio (SSMS)

A week or so ago, I wrote about how to use Snippets in SQL Server Management Studio (SSMS) when you can’t remember the syntax of how to create objects in T-SQL.
Snippets were added reasonably recently compared to templates, which are more appropriate when you are creating an entire script file for a new object. They are easy to use too yet because they don’t appear on the screen by default, many people don’t even realize that they are there. Let’s take a look.
From the View menu, you can choose to view Template Explorer:
When Template Explorer opens, you see a list of predefined templates, plus any that you have created yourself. (One advantage of templates is that they are quite easy to create). In this case I’ve expanded the Credential folder, right-clicked the Create Credential template, then clicked Open.
This then opens a new query window with the template for creating a credential inserted.
At this point, it’s tempting to start editing the template manually, but instead click the Specify Values for Template Parameters button on the toolbar.
This finds all the declared parameter values, and opens a window where you can enter the values.
By completing the values in this window, you avoid the need to have to put the same value in many places. In this example, the name of the credential is used in several places.
Templates are a great way to work with predefined code layouts, more than you can do with snippets. SQL Server Management Studio comes with a large number of T-SQL templates but this feature becomes even more powerful when you create your own.
In a later post, I’ll show you how to create your own snippets and templates.
2017-12-07