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 |
|
Index |
|
Login |
|
Role |
|
Schema |
|
Stored Procedure |
|
Synonym |
|
Table |
|
Trigger |
|
User |
|
User Defined Data Type |
|
User Defined Table Type |
|
User Defined Type |
|
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.
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
Concepts
Transact-SQL IntelliSense Overview
Using Transact-SQL Delimiter Matching