Click here to Skip to main content
13,298,965 members (38,003 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 15 May 2012

Snippet and Surround features in SQL Server 2012

, 15 May 2012
Rate this:
Please Sign up or sign in to vote.
Snippet and Surround features in SQL Server 2012.


The SQL Server 2012 Management Studio now looks like Visual Studio. It now includes more features to attract VS developers.

In this article we will have a look at two new enhancements: the Insert Snippet menu option and the Surround Menu with options.

Using the code  

Insert snippet

The Insert Snippet lets us create the basic structure of a Transact-SQL statement or block.

Getting started

To start the Insert Snippet, right click in the SQL Server Management Studio Script Pane and select Insert Snippet or press Ctrl + K / Ctrl + X

You can easily generate T-SQL statements to create Functions, Indexes, Logins, Roles, Schemas, Stored Procedures, Synonyms, Tables, and Triggers.

Let’s take an example for creating a table.

Select the option Create Table.

The code created is the following: 

CREATE TABLE dbo.Sample_Table
    column_1 int NOT NULL,
    column_2 int NULL

It is useful for creating simple examples for testing purposes.

I reviewed the Stored Procedure and it generates code for three scenarios: these scenarios are basic Stored Procedures, Stored Procedures with Cursors and Stored Procedures with output parameters.

The code generated is pretty simple and useful:

CREATE PROCEDURE dbo.Sample_Procedure
    @param1 int = 0,
    @param2 int 
    SELECT @param1, @param2

Surround with option

Another new option is Surround with

The surround will let us generate BEGIN END clauses, WHILE Loops, and IF conditions easily.

To activate this option, right click in the SQL Server Management Studio Script Pane and select Surround with or press Ctrl + K / Ctrl + S 



''If condition
''IF (Condition)



''While loop
WHILE (Condition) 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United Kingdom United Kingdom
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 15 May 2012
Article Copyright 2012 by Tigya
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid