Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

New toys in SQL Server 2012

By Daniel Calbimonte, (first published: 2012/05/15)

The SQL Server 2012 Management Studio now tries to look like the Visual Studio. It is including more and more features similar to attract VS developers. In this article we are going to look two new enhancements: the Insert snippet menu option and the surround with option.

Insert snippet

The insert snippet let us create code easily. For example we can create tables and views in few seconds. Let’s take a look at it.

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 code to create functions, indexes, logins, roles, schemas, stored procedures, synonyms, tables and triggers. In our example we are going to choose table:

Finally, 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 to create simple examples for testing purposes or to generate code automatically to start with real code for real scenarios.

I reviewed the stored procedure and it generates code for 3 scenarios: These scenarios are the basic procedure, a procedure with cursors and a procedure with output parameters. These simple enhancements will help a lot to Developers and DBAs that use the SQL Server.

 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 the Surround with. To activate this option, right click in the SQL Server Management Studio Script pane and select Surround with or press Ctrl+k,Ctrl+s

The surround with let us generate BEGIN END clauses, WHILE Loops and IF conditions easily:




If condition

IF( Condition )



While loop

WHILE( Condition )




SQL Server is including new features to be easier to use and to create code. SSDT includes even more power, but this is a topic that we will talk about deeply in a future article.


Insert Transact-SQL Snippets

Insert Surround-with Transact-SQL snippets

Total article views: 18300 | Views in the last 30 days: 2
Related Articles

Using Code Snippets in SSMS

Snippets will allow you to code faster by inserting chunks of code with few key strokes.


stored procedure with optional parameters

creating stored procedure with optional parameters


Creating Snippets

I'm not sure if this is still useful and works the same for 2014 and 2016. I've created a few for my...


Auto generate insert Procedure

Auto generate insert Procedure


The Snippet Manager in SQL Prompt

I love SQL Prompt, since it makes T-SQL coding quicker and easier. One of the handiest things is the...