Macros in SQL Server Management Studio

前端 未结 6 655
别那么骄傲
别那么骄傲 2021-02-07 04:47

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 r

相关标签:
6条回答
  • 2021-02-07 05:28

    I usually copy the code into another editor (Notepad++, or Delphi /RAD Studio editor), do my macro stuff, and then paste it back into SSMS.

    0 讨论(0)
  • 2021-02-07 05:30

    What about an AutoHotKey script?

    Depending on the complexity of your templates, you could either

    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.

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

    0 讨论(0)
  • 2021-02-07 05:34

    Was looking for something else, but found this question. If you're still looking for something, try SSMS toolpack: http://www.ssmstoolspack.com/ It has macros and a bunch of other neat things. And it's free!

    0 讨论(0)
  • 2021-02-07 05:36

    If you are using SSMS 2005 upwards it has in built support for templates. It isn't exactly full blown macro's, but non the less it is still pretty useful.

    The syntax is exactly as you have shown in your first code snippet and you simply press Ctrl+Shift+M to bring up a dialog box that prompts you for the values to go into your bits enclosed in angle brackets.

    SQL server generates script in this format if you right click on a table and select "Script Table as" then pick either the insert, update or delete option.

    You can also create your own custom templates, or modify one of the existing built in ones (click on View -> Template explorer to get access to the other inbuilt templates).

    There is a short article on MSDN that explains how to get started with templates.

    0 讨论(0)
  • 2021-02-07 05:48

    For SSMS 2016 you can use my Visual Commander extension. It supports macros recording/playback and custom C#/VB commands for editor text manipulations.

    0 讨论(0)
  • 2021-02-07 05:48

    First code is template from old-good MS Query Analyzer. Shortcut to filling is Ctrl+M (but I'm not sure, maybe it is Ctrl+Shift+M).

    There should be same feature in newer SSMS.

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