Select query shortcut in Azure Data Studio 1.9.0
Asked Answered
M

2

5

How can I create query shortcut for 'select * from' in Azure Data Studio ver 1.9.0? I see option to go to Keyboard shortcuts (Azure Data Studio / Preferences / Keyboard Shortcuts) but no query shortcuts.

When I type select, I do get drop down for selecting sqlSelect but its too cumbersome to edit it and put table name etc in it.

Any options?

Manoff answered 3/9, 2019 at 21:18 Comment(6)
What you are talking about are called Snippets: Creating SQL code snippetsDispassion
It worked. Can you make that as your answer and I can accept it.Manoff
That would be a link only answer, which are frowned upon. If I get a chance later, I'll make a comprehensive answer.Dispassion
@Larnu I disagree, there is quite a difference between snippets and query shortcuts.Schulein
@AnujBalan ever got around to make the query shorcuts work like in Wali's answer? I can't seem to find the option in my settings :/Schulein
@AnujBalan Please mark Walids answer as correct! Thank you :) It works, I just tested a few moments ago.Principate
B
8

To setup query shortcuts, assuming you already set your preferred shortcut(*) to some keyboard key combinations (ex: workbench.action.query.shortcut5:ctrl+5) enter image description here

Now go to Azure Data Studio / Preferences / Settings Search for sql.query.shortcut* and type there you query/store procedure. (ex: sql.query.shortcut5: "Select top 100 * from ") set query shortcut

Barbicel answered 25/6, 2020 at 8:35 Comment(5)
hey Wali, does it still work for you? I can't seem to find this particular setting in my settings... is annoying af.Schulein
I got this to work by adding it manually to the json settings file in version 1.21. Added a bug report to the git repo for azure studios Open the "all commands" line with "ctrl+shift+p". Search for "Preferences: Open Settings (JSON)" . Add in the following line with the " symbols. Change the number after shortcut to change which shortcut should trigger: "sql.query.shortcut4": "SELECT TOP 1000 * FROM "Zaratite
Hi @RemkovanHierden, Yes, me also noticed that after some updates of Azure studioBarbicel
@Schulein by the time writing this comment, I checked again and it was there, I hope you found it as well.Barbicel
@Wali thank you for mentioning it... I didn't check since last update, but now is there! YEY!Schulein
O
2

You can make your own Code Snippets in Azure Data Studio.

  1. Open Command Palette (Ctrl/Cmd + Shift + P) and search for Open User Snippets
  2. Select SQL for your language.
  3. Add a snippet for your query. Such as -
{
"Select All": {
 "prefix": "sqlSelectAll",
 "body": "select * FROM ${1:TableName}",
 "description": "User-defined snippet example 1"
 }
}
  1. Now open a new editor and type your prefix, sqlSelectAll in this case, and it should appear.

Source - https://learn.microsoft.com/en-us/sql/azure-data-studio/code-snippets?view=sql-server-ver15

Observable answered 27/3, 2020 at 22:41 Comment(1)
Code snippets aren't the same as query shortcuts... sometimes you just want a quick peek in your table or a count, without having to add a few lines of code to find that. The correct answer would be the one from Wali, but the clearly existent option is his settings screenshot, is totally missing from me :( .Schulein

© 2022 - 2024 — McMap. All rights reserved.