SQL Server Management Studio中的宏 [英] Macros in SQL Server Management Studio

查看:98
本文介绍了SQL Server Management Studio中的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在SSMS中实现文本编辑宏?我会,例如希望按如下所示转换代码,但只需按一下即可,而不是冗长的正则表达式搜索和替换.

Is there any way to implement text editing macros in SSMS? I would, e.g. like to convert the the code as shown below, but with a key-press, not a long-winded regex search and replace.

此:

INSERT INTO [TABLE]
           ([fieldOne]
           ,[fieldTwo])
     VALUES
           (<fieldOne, datetime,>
           ,<fieldTwo, real(24,0))

必须成为这个:

INSERT INTO [TABLE]
           ([fieldOne]
           ,[fieldTwo])
     VALUES
           (@fieldOne
           ,@fieldTwo)

我知道SSMS本身不支持此功能,但是我也知道它是可扩展的(如果没有文档说明),并且还有一个完全外部的应用程序空间,该应用程序可以将复制的文本,转换并将其粘贴回去,而无需必须打开编辑器,然后将其粘贴,编辑,复制并粘贴回SSMS.

I know SSMS doesn't natively support this, but I also know that it is extensible, if undocumented, and there is also room for a totally external application that will take copied text, transform it, and paste it back, without having to open an editor, paste, edit, copy, and paste back to SSMS.

编辑存储的模板不是一种选择,因为这些模板是动态生成的,并且使用Ctrl + Shift + M也不是一种选择,因为我仍然必须键入每个参数名称,但是没有复制和粘贴的便利在查询编辑器中.

Editing the stored templates is not an option, as these templates are dynamically generated, and using Ctrl+Shift+M is not an option either, as I still have to type each parameter name, but without the convenience of copying and pasting in the query editor.

没有SSMS解决方案!我正在寻找某种外部巫毒可以帮助我做到这一点.

There is no SSMS solution! I am looking for some sort of external voodoo that can help me do this.

推荐答案

AutoHotKey 脚本怎么样?

根据模板的复杂程度,您可以

Depending on the complexity of your templates, you could either

  1. 使用AutoHotKey播放击键 正则表达式搜索所需的内容,以及 替换或
  2. 将模板复制到 剪贴板并对其进行操作 直接在AutoHotKey中 粘贴回去.
  1. use AutoHotKey to play back the keystrokes needed for the regex search and replace, or
  2. copy the template to the clipboard and manipulate it directly within AutoHotKey before pasting it back.

我确定第一个选项会起作用.我还没有尝试第二次.

I'm sure the first option will work. I've not tried the second.

此问题指示如何编写AutoHotKey脚本来侦听键盘和弦.

This question gives an indication of how an AutoHotKey script can be written to listen for keyboard chords.

这篇关于SQL Server Management Studio中的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆