Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

New toys in SQL Server 2012

By Daniel Calbimonte,

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: 14662 | Views in the last 30 days: 13
 
Related Articles
FORUM

stored procedure with optional parameters

creating stored procedure with optional parameters

FORUM

Auto generate insert Procedure

Auto generate insert Procedure

FORUM

create Procedure within Procedure

create Procedure within Procedure

FORUM

ERRORFILE option in BULK INSERT

ERRORFILE option in BULK INSERT

SCRIPT

Store Procedure to create Insert statement from exisiting records

This procedure creates insert statements for the given table and given range of values of primary ke...

Tags
insert    
surround    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones