如何在SQL Server Management Studio中执行单个查询?

时间:2022-01-25 03:52:39

Background: I'm using SQL Server Management Studio 2008 and I have a query window open that contains multiple queries.

背景:我正在使用SQL Server Management Studio 2008,并打开了一个查询窗口,其中包含多个查询。

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.

是否有一个键盘快捷键可以让我执行一个查询而不突出显示我想首先运行的查询?其他一些SQL工具也有缩短功能,可以在光标下面运行查询,将指针放在键盘上,并且远离鼠标。

9 个解决方案

#1


19  

I did some searching and was unable to find any keyboard shortcuts for executing individual lines in SSMS. There is a reference online though.

我进行了一些搜索,但是无法找到任何在SSMS中执行单个行的快捷键。不过网上有参考资料。

http://msdn.microsoft.com/en-us/library/ms174205.aspx

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.

我个人仅仅突出问题的行(Shift +结束或Shift +↓,等等)和按F5。

Ctrl + E works just as well on a Mac.

在Mac电脑上,Ctrl + E也能正常工作。

#2


8  

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

通常的Shift + Arrow或Shift + PgUp / PgDown应用于大多数或所有Windows应用程序……

Then I use Ctrl + E to execute

然后使用Ctrl + E执行

#3


6  

Highlight the query you want to run, then F5.

突出显示要运行的查询,然后是F5。

#4


6  

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.

由于这是最初的要求,DevArt已经将此功能添加到他们的SSMS附加组件。安装后,按Ctrl-Shift-E执行光标下的语句块。

#5


5  

This isn't exactly what the OP was after, but here are two related tips that might help:

这并不是OP的目标,但是这里有两个相关的技巧可以帮助你:

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.

SSMS 2008有一个方便的特性,您可以双击左边的空白(行号在哪里),它将自动展开您的选择,直到包含该行的查询的开始和结束。所以,双击,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.

它还有一个很好的特性,iirc, alt+up/down,或者alt+shift+up/down,它会将你的选择扩展到每一行的开头和结尾,包括你开始的那一行,不管你的光标在这一行的什么位置。这是选择要执行的查询的另一种简便方法。

SSMS 2012 did away with those shortcuts (maybe they exist, but they're not the SAME, by default).

SSMS 2012消除了这些快捷方式(它们可能存在,但默认情况下它们并不相同)。

#6


3  

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

我只是马克线我在(Shift +↓或Shift +结束),然后单击“Alt + X”。

#7


2  

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

使用SSMS 2012,您可以尝试SSMS执行程序外接程序。

Default shortcut Ctrl-Shift-E.

默认快捷键Ctrl-Shift-E。

#8


1  

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.

在显示行号的SSMS 2008R2中,您可以双击查询附近的任何位置的行号,以选择该行的整个查询。这是一个很棒的特性,我一直在使用它。

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.

不幸的是,这个功能在2012年过渡到Visual Studio编辑器时丢失了。我为此创建了一个连接问题,我欢迎对此进行投票。

#9


0  

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

新版本的SSMS正在由微软开发(类似于新版本),叫做SQL Operations Studio。

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

使用SOS(哈哈),你可以按Ctrl+F5,或者像我一样,用Ctrl+Enter替换快捷键。

#1


19  

I did some searching and was unable to find any keyboard shortcuts for executing individual lines in SSMS. There is a reference online though.

我进行了一些搜索,但是无法找到任何在SSMS中执行单个行的快捷键。不过网上有参考资料。

http://msdn.microsoft.com/en-us/library/ms174205.aspx

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.

我个人仅仅突出问题的行(Shift +结束或Shift +↓,等等)和按F5。

Ctrl + E works just as well on a Mac.

在Mac电脑上,Ctrl + E也能正常工作。

#2


8  

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

通常的Shift + Arrow或Shift + PgUp / PgDown应用于大多数或所有Windows应用程序……

Then I use Ctrl + E to execute

然后使用Ctrl + E执行

#3


6  

Highlight the query you want to run, then F5.

突出显示要运行的查询,然后是F5。

#4


6  

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.

由于这是最初的要求,DevArt已经将此功能添加到他们的SSMS附加组件。安装后,按Ctrl-Shift-E执行光标下的语句块。

#5


5  

This isn't exactly what the OP was after, but here are two related tips that might help:

这并不是OP的目标,但是这里有两个相关的技巧可以帮助你:

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.

SSMS 2008有一个方便的特性,您可以双击左边的空白(行号在哪里),它将自动展开您的选择,直到包含该行的查询的开始和结束。所以,双击,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.

它还有一个很好的特性,iirc, alt+up/down,或者alt+shift+up/down,它会将你的选择扩展到每一行的开头和结尾,包括你开始的那一行,不管你的光标在这一行的什么位置。这是选择要执行的查询的另一种简便方法。

SSMS 2012 did away with those shortcuts (maybe they exist, but they're not the SAME, by default).

SSMS 2012消除了这些快捷方式(它们可能存在,但默认情况下它们并不相同)。

#6


3  

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

我只是马克线我在(Shift +↓或Shift +结束),然后单击“Alt + X”。

#7


2  

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

使用SSMS 2012,您可以尝试SSMS执行程序外接程序。

Default shortcut Ctrl-Shift-E.

默认快捷键Ctrl-Shift-E。

#8


1  

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.

在显示行号的SSMS 2008R2中,您可以双击查询附近的任何位置的行号,以选择该行的整个查询。这是一个很棒的特性,我一直在使用它。

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.

不幸的是,这个功能在2012年过渡到Visual Studio编辑器时丢失了。我为此创建了一个连接问题,我欢迎对此进行投票。

#9


0  

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

新版本的SSMS正在由微软开发(类似于新版本),叫做SQL Operations Studio。

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

使用SOS(哈哈),你可以按Ctrl+F5,或者像我一样,用Ctrl+Enter替换快捷键。