tags:

views:

40

answers:

4

Is there a way in Microsoft SQL Server Management Studio, to program a function key? I'd like to map a function key to "SELECT * FROM dbo."

+3  A: 

Yes, there is Tools-->Options-->Enviroment-->Keyboard

there are already a bunch there , you can type anything you want in the Stored Procedure column. However that will just execute, I guess you can do a PRINT 'SELECT * FROM fbo.' in your case

alt text

SQLMenace
That doesn't seem to be working for me. I tried Ctrl+0.
cf_PhillipSenn
works for me, you might have to open a new query window
SQLMenace
I suspect the OP wants the text to be added to the query pane, not the results pane
Ed Harper
+2  A: 

It's outside of the studio but I use AutoHotKey (google it). You can write little keyword macros. Even launch applications with a few keystrokes. All in an effort to reduce time on the mouse.

Chris
I'll check it out. Thanks Chris!
cf_PhillipSenn
+1  A: 

In SSMS:

  • Tools
  • Options
  • Keyboard
  • Select the desire shortcut (only 12 options, 3 of which are hard-coded and cannot be changed, which is better than none, but not by much)
  • Enter what you'd want run (for example, I have CTRL+0 set to "USE tempdb"
  • Save

These hotkeys will not be available to currently opened query windows, only windows opened after you've created them.

Note that if you make it a procedure call, such as as CTRL+1's "sp_who", hilight a block of text, and hit the hot key, the highlit text is passed in as a parameter to the procedure. Try it with CTRL+1 and see. (...and you get lots of fun and games with embedded periods which can be overridden by [bracketing it], but you'll find out about that as you go along.)

Philip Kelley
+1  A: 

I would recommend that you use a free management studio tool called "SSMS Tools Pack" from Mladen Prajdic. It has a feature called SQL snippets where you can map snippets of SQL code to predefined keystrokes ("ssf" + ENTER" will do what you want using the tool).

I use it every day at different clients and its part of my SQL toolkit. Check it out here: www.ssmstoolspack.com.

Eric

Strommy
I like it!Thanks Strommy!
cf_PhillipSenn