Share via


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.

Note

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.

Overview

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

Function

  • Create Inline Table Function

  • Create Multi-Statement Table Function

  • Create Scalar Function

Index

  • Create Index Basic

  • Create Primary XML Index

  • Create Unique Non-Clustered Index

Login

  • Create SQL Authentication Login

  • Create Windows Authentication Login

Role

  • Create Database Role

Schema

  • Create Schema

Stored Procedure

  • Alter Stored Procedure

  • Create Procedure Basic Template

  • Create Procedure with CURSOR OUTPUT Parameter

  • Create Procedure with OUTPUT Parameter

Synonym

  • Create Synonym

Table

  • Add Check Constraint

  • Add Foreign Key

  • Add Primary Key

  • Add Unique Constraint

  • Create Column Default Constraint

  • Create Table

Trigger

  • Create Trigger

User

  • 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

View

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

Example

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.

Ee362022.S_0Prime(en-us,VS.100).gif

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.

Ee362022.S_Table_Create1(en-us,VS.100).gif

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.

Ee362022.S_Table_Create2(en-us,VS.100).gif

See Also

Concepts

Transact-SQL IntelliSense Overview

Using Transact-SQL Delimiter Matching

Troubleshooting Transact-SQL IntelliSense

Transact-SQL Syntax Supported by IntelliSense