Create SQL Code Snippets in Azure Data Studio
27 Nov 2020Introduction
I recently decided to make to move from SSMS to Azure Data Studio due to the fun additional features is brings to the table. I enjoy Visual Studio Code and, my understanding is that Azure Data Studio is built on the same codebase. It is the small things that hooked me like Zen Mode, Source Control Integration and then Notebooks of coarse. I will be writing a post on Notebooks soon.
So today I want to show you how to add your own code snippets. I use INFORMATION_SCHEMA quite often to find a tables or a columns in our databases. So this is what code snippet we will be creating today.
Prerequisites
- Have Azure Data Studio Installed
Creating our first Snippet
- Open Azure Data Studio :)
- Press “CTRL + SHIFT + P” to open the Command Pallet
- Type “User Snippets” into the Command Pallet and Press “ENTER”
- Now type “SQL” and Press “ENTER”
-
This will open “sql.json” file and this is where you will add the code below
"Find Object": { "prefix": "sqlInfo", "body": [ "SELECT * FROM INFORMATION_SCHEMA.${1|COLUMN,TABLE|}S WHERE ${1|COLUMN,TABLE|}_NAME LIKE '%${2:Search}%'" ], "description": "Find Object Information" }
- Save the “sql.json” file and close it
- Now we finally get to use our newly created code snippet, Open a empty sql script
- Type in the prefix we define above “sqlInfo” and press tab
- Now select Table/Column as per the list we defined in our code above, Select what you are looking for and press “TAB” and press “TAB” again to move to the search criteria.
- Type the Table or Column Name you are looking for, then press “TAB” again to move out of the snippet context.
External Links
Disclaimer: Content is accurate at the time of publication, however updates and new additions happen frequently which could change the accuracy or relevance. Please keep this in mind when using my content as guidelines. Please always test in a testing or development environment, I do not accept any liability for damages caused by this content.
If you liked this post, you can share it with your followers or follow me on Twitter!