As we type in SSMS all day long and type the same things over and over, and in case you did not know about the snippet mgr or know how to exploit it…
You can build a library of “Surround With” snippets to save you a BUNCH of keystrokes every day. Below are the instructions along with an attached xml code sample.
- Save the attached to a folder, say: /snippets/
- Create a folder under snippets, say: /snippets/My Snippets/
- So now you have a .snippet file and a folder in: /snippets/
- Go to SSMS and hit: CTRL+K,CTRL+B (hold the CTRL key down and hit K, then B
- Click: ‘Add…’
- Find and select your “My Snippets” folder on your OS
- Back at the Code Snippets Manager, Click: ‘Import…’
- Navigate to your root /snippets/ folder and select the .snippet file that you downloaded from this email
- Select to add this file to your “My Snippets” container (check the box on the right) and click: Finish
- Now you are ready to execute the “Surround With” command you added…
- Either run the command to start off a query, OR, highlight a table name to query. Hit: CTRL+K,S (hit K then S while holding down CTRL)
- Just use your arrow keys and the ENTER to find and select your new command within your “My Snippets” container so you don’t have to leave the keyboard
- Below was the result of me highlighting the fully qualified table name and executing the snippet
SELECT_TOP.SNIPPET
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="https://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <_locDefinition xmlns="urn:locstudio"> <_locDefault _loc="locNone" /> <_locTag _loc="locData">Title</_locTag> <_locTag _loc="locData">Description</_locTag> <_locTag _loc="locData">Author</_locTag> <_locTag _loc="locData">ToolTip</_locTag> <_locTag _loc="locData">Default</_locTag> </_locDefinition> <CodeSnippet Format="1.0.0"> <Header> <Title>SELECT_TOP_1000</Title> <Shortcut>t</Shortcut> <Description>Snippet for SELECT TOP</Description> <Author>Patrick Fitzgerald</Author> <SnippetTypes> <SnippetType>SurroundsWith</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>SELECTOP1000</ID> <ToolTip>SELECT TOP 1000 From Selected Table</ToolTip> <Default>SELECTOP1000</Default> </Literal> </Declarations> <Code Language="SQL"><![CDATA[SELECT TOP 1000 * FROM $selected$$end$;]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>

No comments:
Post a Comment