SEQUENCE object is one of my favorite objects introduced in SQL Server 2012. It is very handy when you need an enhanced functionality in an identity column. Due to its performance & functionality, I use it very frequently, but the issue is, I either need to write the complete script of sequence by myself or I need to use SSMS and then go to database >> Programmability >> Sequence and create a new sequence object as shown in the picture below.
Alternatively, we can create the Sequence object snippet, as shown in the script below. Just copy the given below script and save as “Create Sequence.snippet” and register it. Once registered, you can use it like any other custom snippet.
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://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> </_locDefinition> <CodeSnippet Format="1.0.0"> <Header> <Title>Create Sequence</Title> <Shortcut></Shortcut> <Description>Creates a sequence.</Description> <Author>Muhammad Imran</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>SchemaName</ID> <ToolTip>Name of the schema</ToolTip> <Default>dbo</Default> </Literal> <Literal> <ID>Sequencename</ID> <ToolTip>Name of the Sequence</ToolTip> <Default>Sample_Sequence</Default> </Literal> <Literal> <ID>datatype</ID> <ToolTip>Data type of the column</ToolTip> <Default>int</Default> </Literal> <Literal> <ID>start</ID> <ToolTip>Start Value</ToolTip> <Default>1</Default> </Literal> <Literal> <ID>increment</ID> <ToolTip>Increment Value</ToolTip> <Default>1</Default> </Literal> <Literal> <ID>minvalue</ID> <ToolTip>Min Value</ToolTip> <Default>1</Default> </Literal> <Literal> <ID>maxvalue</ID> <ToolTip>Max Value</ToolTip> <Default>100</Default> </Literal> <Literal> <ID>Cache</ID> <ToolTip>Cache Value</ToolTip> <Default>2</Default> </Literal> </Declarations> <Code Language="SQL"> <![CDATA[CREATE SEQUENCE [$SchemaName$].[$Sequencename$] AS [$datatype$] START WITH $start$ INCREMENT BY $increment$ MINVALUE $minvalue$ MAXVALUE $maxvalue$ CACHE $Cache$ GO ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
Leave a Reply