Steps To Setup Query Shortcuts in SQL Server

Posted on : 12-08-2011 | By : Devi Prasad | In : SQL Server Basics, SQLServerPedia Syndication

Share:

0


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

SELECT top 10 * FROM PRODUCTS

Now instead of writing the query every time and executing it a query short cut can be setup for this query.

Steps to setup query shortcut in SSMS in detail:

1) Select tools menu and then select options

2) In the options expand environment and then click on Keyboard.

3) In the query shortcuts plane give the query in the Stored Procedures section for one of the shortcuts.

query shortcuts

query shortcuts

4) Click on OK.

Now in order to execute the query using shortcut click any where inside the query window and press ctrl+[shortcutnumber] and the query gets executed. Simple!!!

As shown in the screen shot above the shortcut is ctrl+3.

Lets see a more advanced scenario where the query would be

SELECT top 10 * FROM PRODUCTS where productid = 100

In order to execute this query using shortcut just type

   where productid = 100

and select the text and press ctrl+3. Do not forget to add space before the where clause.

Done!.

In order to simplify this we can add the below query as shortcut.

SELECT top 10 * FROM PRODUCTS where productid = 

Now to find top 10 products that have productid as 100 just type 100 select it and press ctrl+3.

Note:
When a new query shortcut is created you have to open a new query in order to use it.
All the open query windows will not have the updated query shortcuts.

(Visited 68 times, 1 visits today)



References : Devi Prasad (sqlserverlearner.com)

Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.


Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.




Write a comment



Tags: , , , ,