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.
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.
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.
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.