SQL Server Management Studio provides a cool feature called ‘Code Snippets’ which can help you to considerably increase your coding speed. Code Snippets are ready made snippets of code, which you can insert into your T-SQL code. As a result, you can type less and generate more code.
Using Code Snippets in your day to day work is a great time saver, since there is no need to remember any syntax while you are creating your tables, stored procedures, indexes and more. You can also create your own custom snippets and add to the pre-defined snippets available in SQL Server.
SQL Snippets can be categorized into two types —
Expansion Snippet Type – CTRL K + X
Surround With Snippet Type – CTRL K + S
In the SSMS IDE, you can bring up the Insert/Expansion code snippet menu by just clicking on CTRL K + X.
You can then navigate through the folders and select the snippet you want to use.
Based on your selection, you will now see the snippet for creating a new non-clustered index.
Similarly if you want to bring up the ‘Surround With‘ snippet, you can do so by just clicking on CTRL K + S.
You can then navigate through the options and select the snippet you want to use.
You can also press CTRL K + B to bring up the Code Snippets Manager, where you can see all the code snippets and manage them.
To summarize, Four reasons why I really like SQL Code Snippets are —
- No need of remembering the complex T-SQL syntax.
- Increased Productivity – Type less and generate more code.
- Code Reuse – Less effort and time spent.
- Ability to create custom snippets for frequently used scripts.
I would highly recommend you to start leveraging the benefits of using ‘SQL Code Snippets’ in your day to day work.
To learn more SQL Tips and Tricks & other Productivity Enhancements in SQL Server Management Studio, please refer my article links below —