Creating Snippets in 2012

  • Hi SSC,

    I'm a big fan of using snippets to reduce typing the same things over and over again. For 2008 I had a piece of freeware[/url] which worked really nicely for snippets, but for 2012, it's no longer free. However with the integration of SQL into visual studio, snippets are now built in to the IDE. The problem is, I have no idea how to use them.

    I've found articles which show how to reference the folder in which they reside and how to put them into the query window, but what I haven't been able to find is how to actually write the XML which constitutes a snippet. The best I've been able to do is try to reverse engineer existing snippets, but that only goes so far.

    Does anyone have a good resource or explanation of the schema of a snippet XML document so I can build my own quicker and more flexibly?

    NOTE: This is about the best example I've been able to find for the purposes of re-engineering

    <?xml version="1.0" encoding="utf-8" ?>

    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

    <CodeSnippet Format="1.0.0">

    <Header>

    <Title>Template - Insert</Title>

    <Description>Demo for Insert Code Snippet.</Description>

    <Author> Ken O. Bonn </Author>

    <SnippetTypes>

    <SnippetType>Expansion</SnippetType>

    </SnippetTypes>

    </Header>

    <Snippet>

    <Declarations>

    <Literal>

    <ID>DatabaseName</ID>

    <ToolTip>Name of database.</ToolTip>

    <Default></Default>

    </Literal>

    </Declarations>

    <Code Language="SQL">

    <![CDATA[

    ------------------------------------------------------

    -- FILENAME: Template-Expansion.snippet

    -- PURPOSE: Template for Expansion (Insert) snippets.

    -- AUTHOR: Ken O. Bonn

    -- DATE: May 15, 2013

    ------------------------------------------------------

    SET NOCOUNT ON;

    EXEC SP_HELPDB $DatabaseName$;

    ]]>

    </Code>

    </Snippet>

    </CodeSnippet>

    </CodeSnippets>

    Executive Junior Cowboy Developer, Esq.[/url]

  • Here's a good article which might help you:

    http://blogs.msdn.com/b/kenobonn/archive/2013/05/15/code-snippets-in-sql-server-2012-for-greater-team-productivity.aspx

    You might also want to check out the Snippets generator utility

    http://snippetsgen.codeplex.com

    [font="Verdana"]Markus Bohse[/font]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply