Rydell
Rydell

Reputation: 4207

How can I execute a single query in SQL Server Management Studio?

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.

Upvotes: 32

Views: 83246

Answers (11)

Master
Master

Reputation: 11

Ctrl k + u will high lite text f5 to run

Upvotes: 0

Rohit Jadhav
Rohit Jadhav

Reputation: 1272

SQL Server Management Studio don't have the feature to execute single SQL statement from the SQL script editor. even we create different shortcut still it doesn't work as we want.

I found a alterative for SQL Server Management Studio => DBeaver , community version is free.

  1. Download DBeaver
  2. Select SQL server option to connect
  3. Download connector if not already installed(Auto suggest, popup will come)
  4. Shortcut to execute SQL statement/Single line query -> Ctl + Enter
  5. To execute SQL script -> Alt + X

Upvotes: 1

Stanislav Stoyanov
Stanislav Stoyanov

Reputation: 2120

With SSMS 2012 you can try SSMS Executor add-in.

Default shortcut Ctrl-Shift-E.

Upvotes: 6

AlexandreG
AlexandreG

Reputation: 1683

A new version of SSMS is in development by Microsoft (kind of new version) it's called SQL Operations Studio.

With SOS (haha) you can hit Ctrl+F5, or — like me — replace the shortcut to Ctrl+Enter

Upvotes: 1

Mayo
Mayo

Reputation: 10772

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.

Upvotes: 22

Nick
Nick

Reputation: 3950

In SSMS 2008R2 with line numbers displayed, you can double-click a line number anywhere adjacent to a query to select the entire query that's part of that line. It's a great feature and I use it all the time.

Unfortunately the feature was lost in the 2012 transition to the Visual Studio editor. I created a Connect issue for this, which I welcome votes on.

Upvotes: 1

ctb
ctb

Reputation: 1222

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).

Upvotes: 5

Alexander Garden
Alexander Garden

Reputation: 4676

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.

Upvotes: 6

gbn
gbn

Reputation: 432200

The usual Shift + Arrow or Shift + PgUp / PgDown that apply to most or all Windows apps...

Then I use Ctrl + E to execute

Upvotes: 9

Justin Niessner
Justin Niessner

Reputation: 245399

Highlight the query you want to run, then F5.

Upvotes: 5

mbp
mbp

Reputation: 1273

I just mark the line I'm on (Shift + or Shift + End), and then click Alt + X.

Upvotes: 2

Related Questions