Nothing is Too Impossible

Nothing is possible.

About

Matthew Heydman's blog: Music, recording, equipment, programming, technicalia, and other stuff

I’ve created some shortcuts in SQL Server 2005 Management Studio - they come in handy time and time again. Management Studio allows us to define “Query Shortcuts”, which are stored procedures that fire when we press a certain keystroke- passing any selected text as a parameter to the procedure. (I think this was the case with Query Analyzer, but I never discovered the feature there).

To define a Query Shortcut, go to the Tools menu in Management Studio, and choose Tools, Options, Environment, Keyboard. Just type in the name of the procedure beside where you see the keystrokes listed.

Management Studio Options Screenshot

So here are a few generic procs that I use all the time. You can tweak them to accomodate your business rules.

  • util_SearchCode
    Searches the definitions of tables, columns, views, defaults, stored procedures, user-defined functions, triggers, etc. etc. and lists any matches to the selected text.
  • util_SearchEntities
    For the db I use at work, one keystroke searches for various customers, clinics, patients, physicians, etc. Either by ID number or by string.
  • util_BitValues
    When I select a number I can quickly see which bit values are turned on… Handy for bitmask columns.
  • util_Top100Rows
    If I highlight a table name, this proc displays the TOP 100 rows of that table. Great for when I need to ascertain the nature of some data or quickly remind myself of a column name.

Download Source Code
By the way, the util_SearchCode proc is designed for use with SQL Server 2005 and will need some modification to work with earlier versions of SQL Server.

How to Use these Procs
1) Download, unzip, and run the scripts via the link above.

2) Type the names of the procs beside the desired keystroke (see screenshot above).

3) In a Query Editor window, select some text and call one of the procs by pressing Ctrl + the number you assigned in #2.

Note that if you want to pass more than one word to a proc in this fashion, you should surround it in single quotes like a string literal.

Leave a Reply