BLOGS BY TOPIC
BLOGS BY AUTHOR
BLOGS BY YEAR
In a previous blog on new features of SQL 2012, I missed out the ability to insert code snippets, and also to embed or surround code in an IF, BEGIN or WHILE block. This blog rectifies this!
Posted by Andy Brown on 15 May 2012
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Code Snippets in SQL Server 2012
VB and C# programmers have had it for years, but SQL programmers can now have it too. It is code snippets.
How Code Snippets Work in SSMS 2012
Here's how it works. You want to create a stored procedure, but can't remember the exact syntax. So you insert a snippet:
Choose the menu option to insert a snippet
Next, choose what you want to insert (there's pretty much every SQL construct in the list):
You can choose what sort of SQL construct you want to insert.
Finally, choose how you want to insert (in this case) a stored procedure:
Here we're choosing to put in a simple stored procedure.
Here's what you get for this example:
-- I'm in a snippety sort of mood ...
CREATE PROCEDURE dbo.Sample_Procedure
@param1 int = 0,
You can now modify this to suit your needs.
Note that you can even create your own custom snippets in SQL.