Assign shortcuts to commands in SQL Server Management Studio


By:   |   Updated: 2007-07-17   |   Comments (5)   |   Related: 1 | 2 | 3 | 4 | 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 Updated: 2007-07-17


get scripts

next tip button



About the author





Comments For This Article




Tuesday, May 14, 2013 - 11:41:52 AM - Greg Robidoux Back To Top (23946)

@Steve - thanks for the feedback. 

What are you looking at trying to do?


Tuesday, May 14, 2013 - 11:40:02 AM - Steve Back To Top (23945)

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


Thursday, December 20, 2012 - 12:48:33 AM - Abrar Back To Top (21043)

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!


Monday, December 03, 2012 - 12:20:05 PM - CK Back To Top (20718)

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


Tuesday, April 17, 2012 - 1:01:45 PM - Ellen Back To Top (16977)

How can you do this in SQL 2012?

Thanks.



download


Recommended Reading

SQL Server Management Studio keyboard shortcuts (Part 1 of 2)

SSMS keyboard shortcuts (Part 2 of 2)

SQL Server Management Studio Keyboard Shortcuts

Display Line Numbers in a SQL Server Management Studio Query Window

Different Options for Query Results in SQL Server Management Studio





get free sql tips
agree to terms


Learn more about SQL Server tools