Click here to Skip to main content
15,896,606 members
Articles / Database Development / SQL Server
Tip/Trick

Snippet and Surround features in SQL Server 2012

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
15 May 2012CPOL1 min read 11.4K   1  
Snippet and Surround features in SQL Server 2012.

Introduction

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

Image 1

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.

Image 2

Select the option Create Table.

Image 3

The code created is the following: 

SQL
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.

Image 4

The code generated is pretty simple and useful:

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

Surround with option

Another new option is Surround with

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

Image 5

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

SQL
''BEGIN END: 
BEGIN 

END

''If condition
''IF (Condition)

BEGIN

END  

''While loop
WHILE (Condition) 
BEGIN
END

License

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


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --