Debunking the Myths: Cloud HA and DR common misconceptions

Learn more about SQL Server tools



solving sql server problems for millions of dbas and developers since 2006 join MSSQLTips for free SQL Server tips


























































   Got a SQL tip?
            We want to know!

Assign shortcuts to commands in SQL Server Management Studio

MSSQLTips author Greg Robidoux By:   |   Read Comments (5)   |   Related Tips: 1 | 2 | 3 | More > SQL Server Management Studio

Problem
The SQL Server management tools offer a lot of hidden features, but finding all of these features is sometimes done by accident or by necessity to get a particular job done.  One particular feature that would be helpful is to assign shortcuts for particular stored procedures that you run quite frequently.  By default SQL Server offers default shortcuts such as Alt+F1 (sp_help), Ctrl+1 (sp_who) and Ctrl+2 (sp_lock).  How can you assign your own frequently used stored procedures to shortcut keys?

Solution
In the query tool you have the ability to assign keyboard shortcuts for stored procedures that you run frequently.  By default SQL Server assigns some of the most common tasks as such sp_help, sp_who and sp_lock to certain key combinations.  But in addition to these 3 predefined keyboard shortcuts SQL Server also offers you the ability to assign some of your own favorite stored procedures.

SQL 2005
To access the screen below, open a query window and select from the menu Tools -> Options and then select Keyboard under the Environment node.

 

SQL 2000
To access the screen below, open query analyzer and select from the menu Tools -> Customize...

 

How to assign a key
At this point you just need to enter the stored procedure that you want to assign to the keyboard shortcut.  By default SQL Server will follow the same rules for finding the stored procedure as when using the query windows. If the stored procedure is not found it will give you an error stating that the stored procedure could not be found 

You can also specify the database where the stored procedure exists such as:

master.dbo.sp_who2

AdventureWorks.HumanResources.uspGetEmployeeList

Here is an example where these two stored procedures have been assigned to a shortcut key.  To run these you just need to issue the correct keyboard combination such as Ctrl+3 or Ctrl+4.

Next Steps



Last Update: 7/17/2007


About the author
MSSQLTips author Greg Robidoux
Greg Robidoux is the President of Edgewood Solutions and a co-founder of MSSQLTips.com.

View all my tips


print tip Print  
Become a paid author





join MSSQLTips for free SQL Server tips     



Comments and Feedback:
Tuesday, April 17, 2012 - 1:01:45 PM - Ellen Read The Tip

How can you do this in SQL 2012?

Thanks.


Monday, December 03, 2012 - 12:20:05 PM - CK Read The Tip

Ellen, it is basically the same. Tools|Options|Keyboard|Query Shortcut. Just one more click will make it.


Thursday, December 20, 2012 - 12:48:33 AM - Abrar Read The Tip

Ellen, we have "query.custom?" tags for assign shortcut for custom queries...

but the problem on my end is that ... how can assign the tags "query.custom?" the value which they will execute?

Kindly share your favor for this issue?

Thank you!


Tuesday, May 14, 2013 - 11:40:02 AM - Steve Read The Tip

One criticism: this should not be called 'Assign shortcuts to commands...', it should be called 'Assign shortcuts to stored procedures...'

I keep tripping over this page thinking it has what I'm really looking for (shortcuts to commands!).


Tuesday, May 14, 2013 - 11:41:52 AM - Greg Robidoux Read The Tip

@Steve - thanks for the feedback. 

What are you looking at trying to do?



Post a Comment or Question

Keep it clean and stay on the subject or we may delete your comment.
Your email address is not published. Required fields are marked with an asterisk (*)

*Name   *Email Notify for updates



Comments
Get free SQL tips:

*Enter Code refresh code


 
Sponsor Information







Copyright (c) 2006-2014 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | about
authors | contribute | feedback | giveaways | free t-shirt | user groups | community | events | first timer?
Some names and products listed are the registered trademarks of their respective owners.