Thursday, June 26, 2014

What is a snippet and how do you insert a snippet in SQL Server?

A snippet is a template of TSQL code that you can use as a basis for writing your TSQL Statements. There are lots of canned templates that makes it easy to insert statements and modify them to suit your needs.

Steps to insert a snippet:

1. Right click the database (here Northwind) in which you want to create snippet and choose New query and New Query window opens(the pane on the right)


2. Right click inside the SQL Query pane and choose Insert Snippet (CTRD+X, CTRL+K) to display the following:



There are many different snippets you can insert and they are categorized as shown in the above to screen shots.

3. Let us say we want to create a table. In this case we insert a statement for creating a table. Click on (or double click) Table


4. Click on Create Table and a code snippet will be inserted. It takes a little while and the following code will be inserted.



This code has all the required items for the syntax. Albeit a simple table with two columns, it is a beginning. You may want to add more data types, more columns, add constraints etc.

No comments: