且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 SQL Server Management Studio 中格式化 SQL

更新时间:2022-06-03 02:24:32

迟到的答案,但希望值得:Poor Man's T-SQL Formatter 是一个开源(免费)T-SQL 格式化程序,具有完整的 T-SQL 批处理/脚本支持(任何 DDL、任何 DML)、SSMS 插件、命令行批量格式化程序和其他选项.

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.

它可在 http://poorsql.com 上立即/在线使用,今天刚刚升级到1.0 版""(它是几个月前的测试版),刚刚获得对 MERGE 语句、OUTPUT 子句和其他挑剔的东西的支持.

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.

SSMS 插件允许您设置自己的热键(默认为 Ctrl-KCtrl-F,以匹配 Visual Studio),并格式化整个脚本或仅格式化您选择/突出显示的代码(如果有).输出格式可自定义.

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.

在 SSMS 2008 中,它与内置的智能感知很好地结合在一起,有效地提供了与 Red Gate 的 SQL Prompt 或多或少相同的基本功能(当然,SQL Prompt 有额外的东西,比如片段,快速对象脚本等).

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 :)