Home > Management Studio, SQLServer, SQLServer 2005, SQLServer 2008, SQLServer 2008 R2 > Create a shortcut for Frequently Used Queries – Management Studio

Create a shortcut for Frequently Used Queries – Management Studio


You can create shortcuts for frequently used queries in Management Studio, some of the shortcuts are predefined, like pressing “Ctrl + 1” will execute “sp_who2”. You can create shortcuts for your own queries or change the existing shortcuts. To create a new shortcut go to Tools > Options in Management Studio.

image

For example, I have created a shortcut for:

SELECT  COUNT(*)
FROM    AdventureWorks2008R2.Person.Address

Now, before you can use the shortcut you need to restart Management Studio. And it’s done, once you restart and login to SSMS, press “Ctrl + 3” or, whatever shortcut assigned to it.

image

and, there’s the result of the query. You can take this trick a step further and generalize it. To do so you need to change the shortcut query, for example, let’s make a shortcut to retrieve a count of rows for any table. For this to work we’ll change the shortcut query as below:

image

Now, we can use the shortcut on any table or view, for this shortcut to take effect you will need to restart SSMS. Once you restart and login to SSMS, use the shortcut as below:

1. Type a Table / View name in Query window
2. Highlight the name
3. Press “Ctrl + 3”

image

You can define up to 12 shortcuts.

Hope This Helps!

Vishal

  1. No comments yet.
  1. No trackbacks yet.