How can I run only the statement that my cursor is included in SQL Server Management Studio?

Like Toad for an Oracle user for a long time, I'm used to hitting Ctrl + Enter and executing only the instructions under the cursor.

In SQL Server Management Studio, pressing F5 runs the entire script. To run only the current operator, I need to manually select the desired operator, and then press F5.

It really annoys me. Does anyone know a keyboard shortcut tool to run only the current statement on SQL Server? I would change tools only for this function.

Note. Oddly enough, even the free Toad for SQL Server does not allow you to run only the statement under the cursor.

+72
database editor sql-server
Aug 13 '09 at 14:31
source share
20 answers

Good, so I get from all these answers: "No, this is not possible."

Edit:

Here is how I was able to do this:

1 - Download SQL Developer

2 - Download jTDS driver

3 - Follow these instructions to add this driver to SQL Developer

4 - Connect to SQL Server using SQL Developer (cool!)

5 - Run and life is good

+17
Aug 13 '09 at 21:04
source share

You can check this add-in for SSMS 2012. Place the cursor on the statement you want to execute and press CTRL + SHIFT + E

SSMS Executor - https://github.com/devvcat/ssms-executor/releases

Update:
The project was transferred to github, and the add-in was rewritten to support SSMS 2014, SSMS 2016. (Previously, the project lived in codeplex, in SSMS Executor - http://ssmsexecutor.codeplex.com/ .)

+34
Jun 24 '13 at 8:17
source share

Use Ctrl + KU to select a line. Then use F5 to launch it.

Although this only works for single line highlighting, I find it quite useful.

Hope it helps !!

+24
Jan 20 '18 at 6:19 06:19
source share

Someone suggested these features in Devart dbForge SQL Complete (add-on for Management Studio), and it is still under development. Let us hope that it ends and will not be left halfway through development.

+9
Mar 15 '11 at 8:35
source share

Note. Oddly enough, even a free toad for SQL Server does not allow you to run just an instruction under the cursor.

It is really annoying that TOAD does not support what it promises:

From TOAD help: [F9 to execute] part of an instruction that can contain one or more statements. You can select part of the instruction by placing the cursor inside or next to the operator or by selecting the operator. Note. A toad considers all contiguous statements (including comments), separated from the cursor or from each other, in less than two empty lines. If an error occurs during the execution of an instruction, an error message appears that allows you to either ignore the error or continue or stop execution.

I tried this a million times, but it just executes the whole script. I wanted to find him in the user support group (toadss (at) yahoogroups.com), but yahoo has the dumbest search base! He can't even find the keyword β€œtoad” in the mailbox group, DOH!

I think TOAD is the best tool for queries, but the lack of this feature also annoys me a lot.

UPDATE: SOLUTION FOUND! I asked this question in the toadss mail group and got an answer. Unlike Oracle, you must separate the SQL Server statements with the GO keyword after each statement. Only if you do this does the F9 button work as expected, following the current instruction.

+6
Sep 07 '09 at 15:06
source share

The above answer helped me create a shortcut to execute the current statement without selecting a request

1 - Click Tools > Options > Environment > Keyboard

2 - for Show commands , set it to SqlComplete10.Common_ExecuteCurrentStatement

3 - To use the new shortcut, install it in the SQL Query Editor

4 - To press the shortcut keys (desired key combination), execute the Ctrl-Enter combination.

5 - Click Assign . Click OK.

+5
Jul 13 '16 at 11:34
source share

I am using a workaround: I am commenting on requests that I am not using. CTRL-K, CTRL-C can be used to comment on selected SQL code. Use CTRL-K, CTRL-U to uncomment. Thus, you can comment on all other requests and execute the one that interests you using F5.

+4
Aug 13 '09 at 14:36
source share

I do not think that this can be done using only a management studio. BUT, you can use the keyboard quick access software (for example, http://www.autohotkey.com/ ) to have a special sequence recorded and assigned to a hot key. In your case, you need:

<home><shift-end><F5> 

This will select the current line and execute it.

+3
Aug 14 '09 at 5:42
source share

Press Ctrl - E when the text is selected.

+2
Aug 13 '09 at 14:34
source share

In Toad for SQL Server, the following default hotkeys can be used for execution:

  • F5: execute all SQL statements in the editor
  • F9: execute SQL statement at current cursor position
  • Shift-F9: execute all SQL statements from the cursor, including the current one at the cursor position.

However, as ercan writes, you need to separate / follow each statement with "GO".

 SELECT TOP 5 * FROM accounts GO SELECT TOP 5 * FROM users GO SELECT TOP 5 * FROM contracts GO 
+2
Jan 20 2018-11-11T00:
source share

If you need to move your hand to the part of the mouse that bothers you, you can hold Ctrl by pressing the up or down arrow key to select a line immediately.

+1
Aug 13 '09 at 14:35
source share

If the solution for the add-on executor (in the top posted answer) does not work properly, I made it work for me (SSMS v17.8.1): the add-in adds a command in the tools: Tools> Execute Inner Statement section.

You can assign a custom keyboard shortcut to it by choosing Tools> Options> Keyboard, then search for "run" in "Show commands containing:" and select " Tools.ExecuteInnerStatement" . Then simply assign the desired keystroke to the "Press shortcut keys:" field and click the "Assign" button.

+1
Jul 19 '18 at 14:53
source share

I used this work around; when the code is not commented out

Ctrl + K + U

(this command selects the current query string) and then

Ctrl + E

(this run highlights the request).

This is useful when you want to run a single line query between some other lines, such as:

  Select top 100 * from [dbo].[Order] Select top 100 * from [dbo].[OrderItem] Select top 100 * from [dbo].[OrderStatus] 
+1
Dec 11 '18 at 15:25
source share

you can always use sqlcmd and osql command line tools. I did a lot of sybase all at the unix command line using a wrapper function that passed my command line to the equivalent (which I consider isql?). I used vi, so maybe I was just crazy ,-)

0
Aug 13 '09 at 14:53
source share

SQL Complete Express Edition has a built-in built-in interface. But you will not get it without custom intellisense.

(I got this from Salamander2007 post)

0
Dec 08 '11 at 3:45 a.m.
source share

Just select (highlight) the one operator you want to run and press F5.

0
Jul 21 '15 at 16:38
source share

You can combine the two tools as follows: SQL Complete from dbForce and AuhotHotkey.

With SQL Complete: you can execute the current statement in the cursor by pressing Ctrl Shift E

The reason I used AutoHotkey is to make life easier :-) using only F6 to execute the current statement by setting the following code in the AutoHotkey script:

 ;SQL EXECUTE THE CURRENT STATEMENT F6:: Send ^+E return 

And you can execute any current statement in the cursor just by pressing F6

But sometimes again my big problem is that I mistakenly press F5 instead of F6: D

0
Nov 30 '15 at 9:18
source share

The Redgate SQL Prompt Extension for SSMS can do this.

It is not free, but in my experience it is worth having. Better intelligence than the standard version of SSMS, tab coloring, tab history (so valuable!), Snippets, executing a single statement (not just one line) and much more.

0
Feb 06 '19 at 14:44
source share

To run only part of a larger script, try this ..

Steps:

  1. Collapse the SQL statement that you want to execute by clicking the minus sign in the left margin next to the statement. This will only show the first line (with an ellipsis "..." to indicate the code no longer shown) and the ending ";" for approval.

  2. Select the line.

  3. Press the [F5] key.

This will only launch the highlighted statement. If you want to execute more than one statement at a time, collapse each statement and select everything you want to run, then press [F5]. This is a workaround, but still much easier than dragging and selecting multiple lines of code each time.

0
Jul 16 '19 at 19:44
source share

The following works for me ... I am using SSMS 2012

1 - Click "Tools"> "Options"> "Keyboard Environment"

2 - For Show commands containing , set Query.Execute for this parameter .

3 - To use the new shortcut in , set it in the SQL Query Editor

4 - To Press a keyboard shortcut , do the Ctrl-Enter combination.

5 - Click Assign. Click OK.

-one
Feb 17 '16 at 22:19
source share



All Articles