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 
AS
    SELECT @param1,@param2

RETURN 0

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:

BEGIN END:

BEGIN


END

If condition

IF( Condition )

BEGIN


END

While loop

WHILE( Condition )

BEGIN


END

Conclusions

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.

 References

Insert Transact-SQL Snippets

Insert Surround-with Transact-SQL snippets

 
Total article views: 18301 | Views in the last 30 days: 1
 
Related Articles
ARTICLE

Using Code Snippets in SSMS

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

FORUM

stored procedure with optional parameters

creating stored procedure with optional parameters

FORUM

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

FORUM

Auto generate insert Procedure

Auto generate insert Procedure

FORUM

create Procedure within Procedure

create Procedure within Procedure

Tags
insert    
surround    
t-sql    
 
Contribute