How can I execute a single query in SQL Server Management Studio?
Solution 1
I did some searching and was unable to find any keyboard shortcuts for executing individual lines in SSMS. There is a reference online though.
http://msdn.microsoft.com/en-us/library/ms174205.aspx
Personally I just highlight the row in question (Shift + End or Shift + ↓, etc.) and hit F5.
Ctrl + E works just as well on a Mac.
Solution 2
The usual Shift + Arrow or Shift + PgUp / PgDown that apply to most or all Windows apps...
Then I use Ctrl + E to execute
Solution 3
Highlight the query you want to run, then F5.
Solution 4
Since this was originally asked, DevArt has added this functionality to their SSMS add-on . After installation, press Ctrl-Shift-E to execute the statement block under the cursor.
Solution 5
This isn't exactly what the OP was after, but here are two related tips that might help:
SSMS 2008 had a handy feature where you can double click the left margin (where the line numbers are) and it will auto-expand your selection to the beginning and end of the query that contains that line. So, double-click, f5.
It also had a nice feature which was, iirc, alt+up/down or maybe alt+shift+up/down, which will extend your selection to the beginning and end of line for each line you move the cursor across, including the one you started on, regardless of where your cursor is on the line. So this is another handy way to select the query you want to execute.
SSMS 2012 did away with those shortcuts (maybe they exist, but they're not the SAME, by default).
sumeet
Updated on August 13, 2020Comments
-
sumeet almost 4 years
Background: I'm using SQL Server Management Studio 2008 and I have a query window open that contains multiple queries.
Is there a keyboard shortcut that will allow me to execute a single query without highlighting the query I would like to run first? Some other SQL tools have shorcuts that run the query that is under the cursor, which keeps the hands on the keyboard, and away from the mouse.
-
Dave Carlile almost 15 yearsTo clarify this a bit, you can use shift+uparrow, shift+downarrow to highlight the query you want, then Ctrl+E to execute it. No mouse involved at all.
-
sumeet almost 15 yearsAh well, it will have to do. Thanks for take the time mmayo and everyone else!
-
Wouter almost 8 yearsOP: "without highlighting the query I would like to run first"
-
Wouter almost 8 yearsctb is assuming line numbers are being displayed, this is the left margin being talked about. Since SSMS 2012 this feature has been lost. If you click (not double click) in the left margin (left from the line-numbers) you will toggle a breakpoint and make it look like the query is selected. Yet, when pressing F5, all the queries in the file will be executed!
-
Wouter almost 8 yearsThere is a free version, and it works for 2012, all the way up to 2016. Thanks!
-
ctb almost 8 yearsNo. There are 2 areas in the left margin. On the far left, there's a gray area for breakpoints, and immediately to the right of that, a white area where you can click and drag to highlight lines. Every code editor I know of does this. Yes, the white area gets bigger if you show line numbers, but it's still there even when they're off (colors could change, depending on theme).
-
Wouter almost 8 yearsAh, thx for pointing that out. Still... it no longer works in 2016... too bad. Hope they fix it soon...
-
jpaugh over 7 yearsNice to know, but when your hands are already on the keyboard, reaching for the mouse is much slower than
End
,Shift
+Home
; orEnd
,Shift
+Up
+Up
+Up
. -
Robotronx over 5 yearsWorked like a charm.
-
Code Novice almost 5 yearsMoving from Oracle after using SQL Developer for so long... this is a nuisance. I have to highlight every single query so I can run it without running all of the other queries I have on a single page?!?!... why does the semi-colon not allow me to run each query individually? The semi-colon should be the stop point imho. As in don't run queries after the semi-colon.
-
Manngo over 2 years@jpaugh You think so?