{"id":71,"date":"2011-08-12T09:30:23","date_gmt":"2011-08-12T09:30:23","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2011\/08\/12\/steps-to-setup-query-shortcuts-in-sql-server\/"},"modified":"2011-08-12T09:30:23","modified_gmt":"2011-08-12T09:30:23","slug":"steps-to-setup-query-shortcuts-in-sql-server","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2011\/08\/12\/steps-to-setup-query-shortcuts-in-sql-server\/","title":{"rendered":"Steps To Setup Query Shortcuts in SQL Server"},"content":{"rendered":"

SQL Server Management studio provides a very useful functionality called query shortcuts<\/strong>. This makes the task of querying the sql server easier. Just by pressing two keys on the keyboard a complex query can be executed.<\/p>\n

Lets take a scenario where a query is very frequently used.<\/p>\n

Lets suppose the query to be
\n[sql]
\nSELECT top 10 * FROM PRODUCTS
\n[\/sql]<\/p>\n

Now instead of writing the query every time and executing it a query short cut can be setup for this query.<\/p>\n

Steps to setup query shortcut in SSMS in detail:<\/strong><\/p>\n

1) Select tools menu and then select options<\/p>\n

2) In the options expand environment and then click on Keyboard.<\/p>\n

3) In the query shortcuts plane give the query in the Stored Procedures section for one of the shortcuts.<\/p>\n

\"query<\/a>
query shortcuts<\/figcaption><\/figure>\n

4) Click on OK.<\/p>\n

Now in order to execute the query using shortcut click any where inside the query window and press ctrl+[shortcutnumber]<\/strong> and the query gets executed. Simple!!!<\/p>\n

As shown in the screen shot above the shortcut is ctrl+3.<\/p>\n

Lets see a more advanced scenario where the query would be
\n[sql]
\nSELECT top 10 * FROM PRODUCTS where productid = 100
\n[\/sql]<\/p>\n

In order to execute this query using shortcut just type
\n[sql]
\nwhere productid = 100
\n[\/sql]<\/p>\n

and select the text and press ctrl+3. Do not forget to add space before the where clause.<\/p>\n

Done!.<\/p>\n

In order to simplify this we can add the below query as shortcut.
\n[sql]
\nSELECT top 10 * FROM PRODUCTS where productid =
\n[\/sql]<\/p>\n

Now to find top 10 products that have productid as 100 just type 100 select it and press ctrl+3.<\/p>\n

Note:<\/strong>
\nWhen a new query shortcut is created you have to open a new query in order to use it.
\nAll the open query windows will not have the updated query shortcuts.<\/p>\n","protected":false},"excerpt":{"rendered":"

SQL Server Management studio provides a very useful functionality called query shortcuts. This makes the task of querying the sql server easier. Just by pressing two keys on the keyboard a complex query can be executed. Lets take a scenario where a query is very frequently used. Lets suppose the query to be [sql] SELECT…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41,3],"tags":[202,203,204,205,206],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/71"}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}