Click here to Skip to main content
Click here to Skip to main content
Go to top

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.

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

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

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

''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)

Share

About the Author

Tigya

United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 15 May 2012
Article Copyright 2012 by Tigya
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid