How can I run just the statement my cursor is on in SQL Server Management Studio?

后端 未结 24 572
夕颜
夕颜 2020-12-04 17:19

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

相关标签:
24条回答
  • 2020-12-04 17:44

    In Toad for SQL Server the following default hot-keys can be used for execution:

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

    However, like 'ercan' wrote, you need to seperate/follow each statement with 'GO'.

    SELECT TOP 5 * FROM accounts
    GO
    
    SELECT TOP 5 * FROM users
    GO
    
    SELECT TOP 5 * FROM contracts
    GO
    
    0 讨论(0)
  • 2020-12-04 17:44

    The following works for me ... I use SSMS 2012

    1 - Click on Tools > Options > Environment Keyboard

    2 - For Show commands containing, set it to Query.Execute

    3 - For Use new shortcut in, set it to SQL Query Editor

    4 - For Press shortcut keys, perform the Ctrl-Enter combination.

    5 - Click on Assign. Click on OK.

    0 讨论(0)
  • 2020-12-04 17:46

    This feature is present in SSMSBoost add-in for SSMS (I am the developer of this add-in):

    Shift-F5 will select the current statement (which allows you to review what you are currently going to execute). Then you press F5 and execute it.

    0 讨论(0)
  • 2020-12-04 17:46

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

    0 讨论(0)
  • 2020-12-04 17:46

    Just select (highlight) the single statement you want to run and hit F5.

    0 讨论(0)
  • 2020-12-04 17:46

    Use Shift+ (arrow down) to select single row, save a button than Ctrl+KU :D lol.

    Then use F5 to run it.

    Hope it help too..

    0 讨论(0)
提交回复
热议问题