SSMS Tips and Tricks 3-15: Using snippets to improve the DROP DATABASE statement

In an earlier post, I showed how to create a DROP DATABASE template in SSMS. I mentioned that a template wasn’t the best option because a command like this is normally inserted into a script; it’s not the whole script.
That’s where snippets shine. Let’s create a snippet for it.
First let’s open Code Snippets Manager (Tools > Code Snippets Manager):
You’ll see the existing snippet folders. I’ve clicked Add, then created a new folder called GL_Snippets. I created a new folder and pointed to it. For this temporary one, I’ve created it in C:\Temp but you would normally use an appropriate folder.
Next I’ve created a file called DropDatabase.snippet in that folder:
I then opened that file using SSMS:
Note that SSMS has a perfectly good XML editor. I’ve then used it to create the snippet file and saved it:
Back in Code Snippets Manager, I’ve clicked Import:
I located the file to import, deselected the My Code Snippets folder, and selected the GL_Snippets folder, then clicked Finish:
If you are prompted about the file already existing, just choose the Overwrite option.
Now let’s try the new snippet. I opened a new query window, and right-clicked in the empty space. We can then see the option for Insert Snippet (note we could have used Ctrl+K, Ctrl+X):
Then select our new DropDatabase snippet:
The snippet will then appear, with the literal parameter highlighted, ready for replacement:
I typed SomeDatabase and then clicked elsewhere, and it’s all magically updated:
This is really useful for any code that you find yourself typing all the time.
2025-07-26