Contents
Creating a custom snippet
Create a Snippets folder somewhere (I like c:SqlSnippets)
Use the following template as your first snippet
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>Logging - Standard Template</Title> <Shortcut></Shortcut> <Description>Insert script to read Logging</Description> <Author>Company Name Here</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Code Language="SQL"> <![CDATA[ SELECT DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), GETDATE()), TimeStamp) AS RunTime , Message , UserName , . . . FROM Logging.dbo.LogTable WITH (NOLOCK) WHERE TimeStamp > DateAdd(MINUTE, -30, GetUtcDate()) ORDER BY TimeStamp ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>Open Code Snippet Manager (^KB)
- Click Add button
- Navigate to your new Snippets folder
- Click the Select Folder button
Expand your Snippets Folder
Cleaning up the Insert Snippet Dialog
Insert Snippet in Query window
- Press ^KX to bring up the Insert snippet window (before our change)
This dropdown is too busy and it is hard to find our custom snippets.
- Go back to the Code Snippets Manager (^KB)
- Open the folder shown in the Location textbox.
- Make a backup folder to save these scripts and move all files into the backup folder
Folder before backup
Folder after backup
Remove Missing Folders
Go back to the Code Snippets Manager and click the *Remove* button for all the missing folders. When you are done, it should look like this.
Insert new Template
Finally, the payoff. Press ^KX to Insert a tempalte. It should be clean like this: