Transact-SQL Code Snippets
- Posted in:
- Development
- SQL Server
- SSMS
- T-SQL
There are certain T-SQL statements whose syntax I have trouble remembering. When those situations arise, I might look up the syntax online; find the same type of object in SSMS, right-click it, script out the object, and use that as a starting point; or find one of my own scripts that has the syntax I'm looking for. Another option that I often overlook is T-SQL code snippets.
What is a code snippet? Here's the definition from the Microsoft documentation:
A Transact-SQL code snippet is a template containing the basic structure of a Transact-SQL statement or block. You can use snippets as a starting point when adding statements in the Database Engine Query Editor. You can insert the pre-defined snippets supplied with SQL Server, or create your own.
Here's what it looks like in SSMS:
- Right-click in an SSMS window and click "Insert Snippet..."
- A drop-down list of snippet categories appears. Double-click one of the category folders to see the snippets in that group.
- A drop-down list of code snippets appears. Hover your mouse over any of them to see the snippet definition tooltip. Double-click one to insert the code to the SSMS window.
- If the snippet has replacement points (highlighted in yellow), the TAB key will cycle through them allowing you to conveniently replace each with the values you want. If you rest your mouse pointer on a replacement point, a tooltip appears with a description.
SSMS has pre-defined snippets for the following categories:
- Function
- Index
- Login
- Role
- Schema
- Stored Procedure
- Synonym
- Table
- Trigger
- User
- User Defined Data Type
- User Defined Table Type
- User Defined Type
- View
Check 'em out. And happy coding!
(Would you like to create your own, custom code snippets? Continue reading...)
Comments