#0139 – SQL Server – Productivity feature – customize keyboard shortcuts


Recently, I was working with a developer colleague of mine to troubleshoot an issue he had with one of his queries. A stored procedure he wrote was consuming data from another procedure and was not functioning as expected. I suspected the issue to be a missing change in the related stored procedure.

The easiest way to verify this is obviously to script out the object and verify for the existence of the required code. Scripting out a programmability object (a stored procedure, function or a view) can be done in any one of the following ways:

  1. Script the object using the Object Explorer
  2. Query the catalog view – sys.sql_modules
  3. Use the sp_helptext system stored procedure

The recommended way is of course, to use the Object Explorer to script out the object. However, the fastest method for most practical purposes is using the system stored procedure sp_helptext.

sp_helptext takes at least one parameter – the object name, with a normal usage similar to the one shown below:

USE AdventureWorks2008R2
GO
--Normal implementation
sp_helptext uspGetBillOfMaterials
GO

Scripted object using sp_helptext

However, there is another way, which is even faster than typing in sp_helptext – which my colleague was surprised to learn about. That method is to customize the keyboard settings in SSMS such that any key one of the various supported, customizable key combinations stands for executing the system stored procedure sp_helptext.

Customizing the SSMS Keyboard

In order to customize the keyboard settings for your SSMS instance, here are the simple steps that need to be followed:

  1. Navigate out to Tools –> Options
  2. Within the Options window, expand the “Environment” node and navigate to the “Keyboard” node
  3. Navigate to the “Query shortcuts” node by expanding the “Keyboard” node
  4. Notice that various key combinations and assigned stored procedures to be executed are listed in the “Query shortcuts” node
  5. Against the preferred key combination, enter the stored procedure that you would like to execute

Keyboard customization in SSMS

As you can see from the screenshot above, the following are the default key assignments that come with SSMS:

  • Alt + F1 = sp_help
  • Ctrl + 1 = sp_who
  • Ctrl + 2 = sp_lock

In my case, I had the sp_helptext added as the key combination Ctrl+F1.

Please restart the SSMS after making changes to the keyboard configuration.

Using the customization

Once the keyboard combinations are assigned, there is no longer a need to type in sp_helptext anymore. Simply selecting the object name and using the key combination defined (in my case, Ctrl+F1), executes the stored procedure and results are returned.

Using the keyboard customization in SSMS

I hope you liked today’s tip!

References:

Until we meet next time,

Be courteous. Drive responsibly.

Subscribe to my posts via E-mail: Subscribe here | Read my posts via your favourite RSS reader: Click Here! | Tweet to @nakulv_sql

Advertisement

4 thoughts on “#0139 – SQL Server – Productivity feature – customize keyboard shortcuts

  1. Nakul Vachhrajani

    Hello, Ramkoti!

    The screenshots in this post are from a SQL Server 2012 (CTP) instance. The instructions for the RTM release are also similar. What is the exact confusion that you are having? Maybe that will help me help you out in a better way.

    Like

    Reply
  2. ramkoti

    Thank you Nakul,

    It’s my mistake. Now i got it.

    In SQL Server 2012, Under Keyboard Menu, there are 2 sub menus. I have not seen these sub menus. But in SQL Server 2008, we have only Keyboard menu.

    Like

    Reply

Let me know what you think about this post by leaving your feedback here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.