As a long time Toad for Oracle user, I have gotten used to hitting Ctrl+Enter and having just the statement under the cursor be executed.
In SQL Server Management St
SQL Complete Express edition has this built in. But you don't get it without the custom intellisense.
(I got this from Salamander2007's post)
Above answer helped me to create a shortcut to Execute current Statement without selecting the query
1 - Click on Tools > Options > Environment > Keyboard
2 - For Show commands containing, set it to SqlComplete10.Common_ExecuteCurrentStatement
3 - For Use new shortcut in, set it to SQL Query Editor
4 - For Press shortcut keys(desired shortcut key), perform the Ctrl-Enter combination.
5 - Click on Assign. Click on OK.
I don't think this is possible to do using just the management studio. BUT you can use keyboard shortcut software (e.g. http://www.autohotkey.com/) to have a special sequence recorded and assigned to a hotkey. In your case you need:
<home><shift-end><F5>
This will select the current line and execute it.
I used this work around; when code is not commented out
Ctrl + K + U
(this command highlight current query line) and then
Ctrl + E
(this run highlighted query).
It is useful when you want to run a single line query between some other lines like :
Select top 100 * from [dbo].[Order]
Select top 100 * from [dbo].[OrderItem]
Select top 100 * from [dbo].[OrderStatus]
Note: Oddly enough, even the free Toad for SQL Server does not let you run just the statement under the cursor.
It is really annoying that TOAD does not hold to what it promises:
From TOAD help: [F9 to execute] a portion of a statement, which can contain one or more statements. You can select the portion of the statement by placing the cursor within or adjacent to the statement, or by selecting the statement. Note: Toad considers "adjacent" all statements (including comments) separated from the cursor or from each other by fewer than two blank lines. If an error occurs during statement execution, an error message displays, allowing you to either ignore the error and continue or to abort execution.
I tried it million times but it simply executes the whole script. I wanted to search for it in the user support group (toadss(at)yahoogroups.com) but yahoo has the stupidest search facility ever! It can't even find the keyword "toad" in the toad mail group, DOH!
I think TOAD is the best querying tool ever, but the lack of this feature really annoys me too.
UPDATE: SOLUTION FOUND! I asked this issue in toadss mail group and got the answer. Unlike Oracle, you have to separate statements in SQL Server with the keyword GO after each statement. Only if you do that the F9 button works as expected, executing the current statement.
You can combine the two Tools as follow : SQL Complete from dbForce and AuhotHotkey.
With SQL Complete: you can execute the current statement at the cursor, by pressing the combination Ctrl Shift E
The reason that I used the AutoHotkey is to make life easier :-) by using just F6 to execute the current statement, by setting the following code in AutoHotkey script:
;SQL EXECUTE THE CURRENT STATEMENT
F6::
Send ^+E
return
And voilà you can execute any current statement at the cursor by just pressing F6
But sometimes, again my big problem is I mistakely press F5 instead of F6 :D