Format SQL in SQL Server Management Studio

后端 未结 2 668
野趣味
野趣味 2020-11-29 15:36

In Visual Studio & other IDEs, you can easily auto format your code with a keyboard shortcut, through the menu, or automatically as you type.

I was wondering if

相关标签:
2条回答
  • 2020-11-29 16:01

    Late answer, but hopefully worthwhile: The Poor Man's T-SQL Formatter is an open-source (free) T-SQL formatter with complete T-SQL batch/script support (any DDL, any DML), SSMS Plugin, command-line bulk formatter, and other options.

    It's available for immediate/online use at http://poorsql.com, and just today graduated to "version 1.0" (it was in beta version for a few months), having just acquired support for MERGE statements, OUTPUT clauses, and other finicky stuff.

    The SSMS Add-in allows you to set your own hotkey (default is Ctrl-K, Ctrl-F, to match Visual Studio), and formats the entire script or just the code you have selected/highlighted, if any. Output formatting is customizable.

    In SSMS 2008 it combines nicely with the built-in intelli-sense, effectively providing more-or-less the same base functionality as Red Gate's SQL Prompt (SQL Prompt does, of course, have extra stuff, like snippets, quick object scripting, etc).

    Feedback/feature requests are more than welcome, please give it a whirl if you get the chance!

    Disclosure: This is probably obvious already but I wrote this library/tool/site, so this answer is also shameless self-promotion :)

    0 讨论(0)
  • 2020-11-29 16:01

    There is a special trick I discovered by accident.

    1. Select the query you wish to format.
    2. Ctrl+Shift+Q (This will open your query in the query designer)
    3. Then just go OK Voila! Query designer will format your query for you. Caveat is that you can only do this for statements and not procedural code, but its better than nothing.
    0 讨论(0)
提交回复
热议问题