SQL Management Studio - Execute current line
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....
![mawaldne](https://i.stack.imgur.com/KJHQy.png?s=256&g=1)
Comments
-
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 about 14 yearsThats too bad. I can live with highlighting the query, I just wanted to save some keystrokes. Thanks for the help
-
robaker about 11 yearsThis selects everything up to the top of the file, in SQL Management Studio 2008, not just the current statement
-
jinglesthula over 10 yearsI think it's a little savings that adds up over time to be quite significant.
-
Obsidian Phoenix over 9 yearsOld, 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 over 9 yearsShift+Home, not Ctrl+Shift+Home :)
-
th1rdey3 about 9 yearsI use sql developer, so i am using Ctrl+Enter (^_^)
-
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 over 8 yearsThis assumes your query is only written on one line. This does not work for multi line queries
-
saravana_pc about 8 yearsThis is by far the best solution for this problem
-
menkow almost 8 yearsYes, it is the best answer without add-ons!
-
pmbanka over 7 yearsFor those wondering... Options -> Text Editor -> All Languages -> Line numbers
-
Alec Effrat over 3 yearsthis 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