SQL Management Studio - Execute current line

15,807

Solution 1

Unfortunately no there is no such keyboard shortcut in the MSDN list of keyboard shortcuts for SMSS, and I don't see any way of recording a macro to do so. The only solutions I've found require creating an add-in which is quite a bit of work for a little savings.

Solution 2

In options you can configure line numbers to be displayed, then you can just click on a line number, which will highlight the whole line.

Solution 3

Install SQL Complete Express. Its an SSMS plugin that free (also a paid version) and it allows using CTRL+SHIFT+E to execute current statement, I have remapped it to F9 as I use Toad frequently too.

I tried several others but they either didn't work with SSMS 2012 or I just didn't get on with them.

I find the intellisense quicker than the built in version to.

Solution 4

If you are able to use SSMS 2012 then you can use the SSMS Executor add in as mentioned by st-stoqnov in his answer to a similar question.

An Alpha release is also available for SSMS 2014/2016/2017.

Solution 5

In SQL after concluding a statement and as along as your cursor is at the end of the line all you have to do it hit SHIFT+HOME and it will highlight the entire statement and you can then proceed to press f5....

Share:
15,807
mawaldne
Author by

mawaldne

Always be learning.

Updated on June 12, 2022

Comments

  • mawaldne
    mawaldne about 2 years

    In SQL Server 2008 Management studio, I can hit F5 to execute everything in the current query window. I can also highlight a query, and hit F5 to run that highlighted query.

    Instead of having to highlight a query, is there a way I can run the single query my cursor is on, or run a query my cursor is on up to a the first ';'?

  • mawaldne
    mawaldne about 14 years
    Thats too bad. I can live with highlighting the query, I just wanted to save some keystrokes. Thanks for the help
  • robaker
    robaker about 11 years
    This selects everything up to the top of the file, in SQL Management Studio 2008, not just the current statement
  • jinglesthula
    jinglesthula over 10 years
    I think it's a little savings that adds up over time to be quite significant.
  • Obsidian Phoenix
    Obsidian Phoenix over 9 years
    Old, I know, but you have no idea how happy this made me. I had Toad for Oracle in my last job 2 years ago, and have been lamenting this feature since I moved to a SQL-only house.
  • mikus
    mikus over 9 years
    Shift+Home, not Ctrl+Shift+Home :)
  • th1rdey3
    th1rdey3 about 9 years
    I use sql developer, so i am using Ctrl+Enter (^_^)
  • Govind Rai
    Govind Rai over 8 years
    +1 I actually never knew this! This is actually a solid alternative to the question being asked since technically there is no such feature provided by Microsoft.
  • Govind Rai
    Govind Rai over 8 years
    This assumes your query is only written on one line. This does not work for multi line queries
  • saravana_pc
    saravana_pc about 8 years
    This is by far the best solution for this problem
  • menkow
    menkow almost 8 years
    Yes, it is the best answer without add-ons!
  • pmbanka
    pmbanka over 7 years
    For those wondering... Options -> Text Editor -> All Languages -> Line numbers
  • Alec Effrat
    Alec Effrat over 3 years
    this answer inspired me to just write an autohotkey script. It's funny I didn't even know I was missing this feature... but the AHK is so nice... also I have it do down arrow so i can hit F6 and have it execute this row, then advance to next row and hit F6 again, voila... I'm sending it to a Remote Desktop Connection so I detect that window... but here is my AutoHotKey .ahk file SetTitleMatchMode RegEx #IfWinActive .*Remote Desktop Connection.* ^+r:: Send,{Home}+{Down}{F5} return