Using Transact-SQL Code Snippets

The Transact-SQL editor Transact-SQL Code Snippets feature allows you to quickly code common Transact-SQL programming patterns. This topic provides an overview of the code snippets that are available in the Transact-SQL editor, describes how to insert code snippets, and demonstrates using the CREATE TABLE code snippet.


The availability of a Transact-SQL Code Snippet does not guarantee that it is supported by the Visual Studio project or database. The Transact-SQL editor provides the same list of code snippets for all scenarios of editing .sql files.


Transact-SQL Code Snippets are always available in the Transact-SQL editor, even when the editor is not associated with a project or connected to an instance of SQL Server. The following code snippets are available to help make your programming experience more productive:

Object group

Available code snippets


  • Create Inline Table Function

  • Create Multi-Statement Table Function

  • Create Scalar Function


  • Create Index Basic

  • Create Primary XML Index

  • Create Unique Non-Clustered Index


  • Create SQL Authentication Login

  • Create Windows Authentication Login


  • Create Database Role


  • Create Schema

Stored Procedure

  • Alter Stored Procedure

  • Create Procedure Basic Template

  • Create Procedure with CURSOR OUTPUT Parameter

  • Create Procedure with OUTPUT Parameter


  • Create Synonym


  • Add Check Constraint

  • Add Foreign Key

  • Add Primary Key

  • Add Unique Constraint

  • Create Column Default Constraint

  • Create Table


  • Create Trigger


  • Create User as DBO

User Defined Data Type

  • Create User-Defined Data Type

User Defined Table Type

  • Create User-Defined Table Type

User Defined Type

  • Create User-Defined Type


  • Create View

Inserting Transact-SQL Code Snippets

There are three ways to open the Transact-SQL Code Snippet menu:

  • Use the keyboard shortcut: Ctrl+K, followed by Ctrl+X

  • Use the Edit menu: Select IntelliSense, then select Insert Snippet…

  • Right-click the Transact-SQL editor: Select Insert Snippet…

After the Transact-SQL Code Snippet menu is open, select the type of code snippet you want. After the code snippet is created, use the Tab key to move to syntax that you may want to change.


The following example shows how to use the CREATE TABLE code snippet. First, open the Transact-SQL Code Snippet menu using one of the methods described in the previous heading. Then type Table or select Table from the menu.


After you select Table from the menu, the list of available code snippets for the table object appears. Type Create Table or select Create Table from the menu to insert the corresponding Transact-SQL code onto the Transact-SQL editor.


The CREATE TABLE code snippet appears on the Transact-SQL editor. To customize the code for your application, press the Tab key to change the name or value of the various items that are highlighted.


See Also


Transact-SQL IntelliSense Overview

Using Transact-SQL Delimiter Matching

Troubleshooting Transact-SQL IntelliSense

Transact-SQL Syntax Supported by IntelliSense