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?

Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
  • 3
    What you are talking about are called Snippets: [Creating SQL code snippets](https://learn.microsoft.com/en-us/sql/azure-data-studio/code-snippets) – Thom A Sep 03 '19 at 21:20
  • It worked. Can you make that as your answer and I can accept it. – Anuj Balan Sep 04 '19 at 16:39
  • That would be a link only answer, which are frowned upon. If I get a chance later, I'll make a comprehensive answer. – Thom A Sep 04 '19 at 16:59
  • 2
    @Larnu I disagree, there is quite a difference between snippets and query shortcuts. – FAB Aug 21 '20 at 08:16
  • 1
    @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 :/ – FAB Aug 21 '20 at 08:17
  • @AnujBalan Please mark Walids answer as correct! Thank you :) It works, I just tested a few moments ago. – Christian Aug 29 '23 at 11:32

2 Answers2

6

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

Walid Haidari
  • 125
  • 2
  • 10
  • 1
    hey Wali, does it still work for you? I can't seem to find this particular setting in my settings... is annoying af. – FAB Aug 21 '20 at 08:10
  • 2
    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 " – Remko van Hierden Sep 18 '20 at 11:09
  • Hi @RemkovanHierden, Yes, me also noticed that after some updates of Azure studio – Walid Haidari Sep 30 '20 at 06:28
  • 2
    @FAB by the time writing this comment, I checked again and it was there, I hope you found it as well. – Walid Haidari Sep 30 '20 at 06:28
  • 1
    @Wali thank you for mentioning it... I didn't check since last update, but now is there! YEY! – FAB Sep 30 '20 at 09:57
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

addybist
  • 461
  • 1
  • 4
  • 13
  • 3
    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 :( . – FAB Aug 21 '20 at 08:15