How to Create Query Shortcuts in SQL Server Management Studio

How to Create Query Shortcuts in SQL Server 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_who". You can create shortcuts for your own queries or change the existing shortcuts.

To create a new shortcut, go to Tools > Options > Environment > Keyboard in Management Studio.
For example, you can create a shortcut for:

SELECT  COUNT(*)
FROM    AdventureWorks2008R2.Person.Address


Before you can use the shortcut you will need to restart Management Studio.

To use this shortcut:
1. Restart Management Studio/Login to an instance,
2. Press "Ctrl + 3" (or the key you have assigned in your environment)
3. It will run the specified query and return the results.



You can also generalize the shortcut as below:

For example, create a shortcut for:

SELECT  COUNT(*)


 

To use this shortcut:
1. Restart Management Studio/Login to an instance,
2. Type fully qualified name of a table/view, e.g. Database.Schema.Table, (if you are in proper context you can also user Schema.Table or Table)
3. Highlight the name and press "Ctrl + 3" (or the key you have assigned in your environment)
4. It will run the specified query and return the results.




See Also


Leave a Comment
  • Please add 4 and 8 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 3. Comment: Changed tags "SQL 2005", "SQL 2008", "SQL 2008 R2" to "SQL Server 2005", "SQL Server 2008", and "SQL Server 2008 R2", removed tag "SQL"

  • Maheshkumar S Tiwari edited Revision 1. Comment: Added tags

Page 1 of 1 (2 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Maheshkumar S Tiwari edited Revision 1. Comment: Added tags

  • Richard Mueller edited Revision 3. Comment: Changed tags "SQL 2005", "SQL 2008", "SQL 2008 R2" to "SQL Server 2005", "SQL Server 2008", and "SQL Server 2008 R2", removed tag "SQL"

Page 1 of 1 (2 items)