SQL管理工作室的SQL格式化程序

时间:2023-02-03 03:34:54

I was wondering if there is a plugin/tool for SQL Server Management Studio that will format your SQL?

我想知道是否有SQL Server Management Studio的插件/工具可以格式化您的SQL?

I'm working with some large-ish stored procs that are a mangled mess of poorly formatted SQL and it'd be nice if I could just go "Select All -> Format SQL"

我正在处理一些大型存储的proc它们是格式化不好的SQL,如果我可以选择"Select All -> Format SQL"

11 个解决方案

#1


92  

Today I discovered Apex SQL Refactor. It is a free plugin. Integrates with SSMS. Downside is that it is an all or nothing process. It does not refactor as you type.

今天我发现了Apex SQL重构。这是一个免费的插件。集成了地对地导弹。缺点是,这是一个要么全部要么没有的过程。它不会在你输入时重构。

#2


220  

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.

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

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

它可以在http://poorsql.com上即时/在线使用,今天刚升级到“1.0版”(在测试中测试了几个月),刚刚获得了对合并语句、输出子句和其他繁琐内容的支持。

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插件允许您设置自己的热键(默认为Ctrl-K, Ctrl-F,以匹配Visual Studio),并格式化整个脚本或您选中/突出显示的代码(如果有的话)。输出格式是可定制的。

In SSMS 2008 it combines nicely with the built-in intellisense, 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).

在SSMS 2008中,它与内置的intellisense很好地结合在一起,有效地提供了与Red Gate的SQL Prompt几乎相同的基本功能(SQL Prompt当然也有额外的功能,比如代码片段、快速对象脚本等等)。

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

披露:这可能已经很明显了,但我写了这个库/工具/站点,所以这个答案也是无耻的自我推销:)

#3


77  

There is a special trick I discovered by accident.

我偶然发现了一个特殊的诀窍。

  1. Select the query you wish to format.
  2. 选择希望格式化的查询。
  3. Ctrl+Shift+Q (This will open your query in the query designer)
  4. Ctrl+Shift+Q(这会在查询设计器中打开查询)
  5. 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.
  6. 那就去好了!查询设计器将为您格式化查询。需要注意的是,您只能对语句而不是过程代码这样做,但这总比什么都不做要好。

#4


22  

Red-Gate makes a couple, either Sql Prompt Pro or Sql Refactor. There are a million others out there that do not plug into management studio, but Red-Gate makes the only plugin I know of and it works very well. They also provide intelli-sense and a few other useful features.

Red-Gate可以使用Sql Prompt Pro或Sql重构。还有成千上万的插件没有插入到management studio中,但是Red-Gate是我所知道的唯一一个插件,它运行得非常好。它们还提供了智能感知和一些其他有用的特性。

http://www.red-gate.com/products/SQL_Prompt/index.htm

http://www.red-gate.com/products/SQL_Prompt/index.htm

#5


19  

This is a free, online one: http://www.sqlinform.com/ (requires Java Runtime Environment)

这是一个免费的在线版本:http://www.sqlinform.com/(需要Java运行时环境)

#6


9  

It is not built in, but it's fast to use it. :) http://www.dpriver.com/pp/sqlformat.htm

它不是内置的,但是使用起来很快。):http://www.dpriver.com/pp/sqlformat.htm

#7


7  

Not a plugin for SSMS, but I find this handy to keep as a bookmark in my browser: http://www.dpriver.com/pp/sqlformat.htm

虽然不是SSMS的插件,但我发现这在我的浏览器中很容易作为书签保存:http://www.dpriver.com/pp/sqlformat.htm

Edit: Oops - I just noticed they have versions for SSMS, Visual Studio, and a desktop version etc. Haven't tried them personally yet.

编辑:糟糕——我刚刚注意到他们有SSMS、Visual Studio和桌面版等版本。我还没有亲自尝试过。

#8


5  

This one (Gudu Software) is pretty good, works in Management Studio and is pretty cheap. It needs more options in my opinion but haven't used it for a few months, maybe they've added some new features. I was happy with it when I used it. Also has a free online version.

这个(Gudu软件)非常好,在管理工作室工作,而且非常便宜。在我看来,它需要更多的选择,但已经有几个月没有使用它了,也许他们已经添加了一些新功能。当我使用它的时候,我很高兴。还有一个免费的在线版本。

#9


5  

SSMS Tools Pack does a good job of formatting and the other tools in the pack come in quite handy

SSMS工具包在格式化方面做得很好,包中的其他工具也很方便

#10


2  

This web site here does basic SQL keyword capitalisation:

此网站提供基本的SQL关键字大小写:

http://www.ascdesc.com

http://www.ascdesc.com

#11


1  

Or you could try my formatter.It is not free. it is a command line tool and it can integrated with SSMS as an external tool.... Tidycode T-Sql Formatter

或者你可以试试我的格式化程序。它不是免费的。这是一个命令行工具,它可以结合地对地导弹作为外部工具....Tidycode t - sql格式化程序

#1


92  

Today I discovered Apex SQL Refactor. It is a free plugin. Integrates with SSMS. Downside is that it is an all or nothing process. It does not refactor as you type.

今天我发现了Apex SQL重构。这是一个免费的插件。集成了地对地导弹。缺点是,这是一个要么全部要么没有的过程。它不会在你输入时重构。

#2


220  

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.

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

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

它可以在http://poorsql.com上即时/在线使用,今天刚升级到“1.0版”(在测试中测试了几个月),刚刚获得了对合并语句、输出子句和其他繁琐内容的支持。

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插件允许您设置自己的热键(默认为Ctrl-K, Ctrl-F,以匹配Visual Studio),并格式化整个脚本或您选中/突出显示的代码(如果有的话)。输出格式是可定制的。

In SSMS 2008 it combines nicely with the built-in intellisense, 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).

在SSMS 2008中,它与内置的intellisense很好地结合在一起,有效地提供了与Red Gate的SQL Prompt几乎相同的基本功能(SQL Prompt当然也有额外的功能,比如代码片段、快速对象脚本等等)。

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

披露:这可能已经很明显了,但我写了这个库/工具/站点,所以这个答案也是无耻的自我推销:)

#3


77  

There is a special trick I discovered by accident.

我偶然发现了一个特殊的诀窍。

  1. Select the query you wish to format.
  2. 选择希望格式化的查询。
  3. Ctrl+Shift+Q (This will open your query in the query designer)
  4. Ctrl+Shift+Q(这会在查询设计器中打开查询)
  5. 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.
  6. 那就去好了!查询设计器将为您格式化查询。需要注意的是,您只能对语句而不是过程代码这样做,但这总比什么都不做要好。

#4


22  

Red-Gate makes a couple, either Sql Prompt Pro or Sql Refactor. There are a million others out there that do not plug into management studio, but Red-Gate makes the only plugin I know of and it works very well. They also provide intelli-sense and a few other useful features.

Red-Gate可以使用Sql Prompt Pro或Sql重构。还有成千上万的插件没有插入到management studio中,但是Red-Gate是我所知道的唯一一个插件,它运行得非常好。它们还提供了智能感知和一些其他有用的特性。

http://www.red-gate.com/products/SQL_Prompt/index.htm

http://www.red-gate.com/products/SQL_Prompt/index.htm

#5


19  

This is a free, online one: http://www.sqlinform.com/ (requires Java Runtime Environment)

这是一个免费的在线版本:http://www.sqlinform.com/(需要Java运行时环境)

#6


9  

It is not built in, but it's fast to use it. :) http://www.dpriver.com/pp/sqlformat.htm

它不是内置的,但是使用起来很快。):http://www.dpriver.com/pp/sqlformat.htm

#7


7  

Not a plugin for SSMS, but I find this handy to keep as a bookmark in my browser: http://www.dpriver.com/pp/sqlformat.htm

虽然不是SSMS的插件,但我发现这在我的浏览器中很容易作为书签保存:http://www.dpriver.com/pp/sqlformat.htm

Edit: Oops - I just noticed they have versions for SSMS, Visual Studio, and a desktop version etc. Haven't tried them personally yet.

编辑:糟糕——我刚刚注意到他们有SSMS、Visual Studio和桌面版等版本。我还没有亲自尝试过。

#8


5  

This one (Gudu Software) is pretty good, works in Management Studio and is pretty cheap. It needs more options in my opinion but haven't used it for a few months, maybe they've added some new features. I was happy with it when I used it. Also has a free online version.

这个(Gudu软件)非常好,在管理工作室工作,而且非常便宜。在我看来,它需要更多的选择,但已经有几个月没有使用它了,也许他们已经添加了一些新功能。当我使用它的时候,我很高兴。还有一个免费的在线版本。

#9


5  

SSMS Tools Pack does a good job of formatting and the other tools in the pack come in quite handy

SSMS工具包在格式化方面做得很好,包中的其他工具也很方便

#10


2  

This web site here does basic SQL keyword capitalisation:

此网站提供基本的SQL关键字大小写:

http://www.ascdesc.com

http://www.ascdesc.com

#11


1  

Or you could try my formatter.It is not free. it is a command line tool and it can integrated with SSMS as an external tool.... Tidycode T-Sql Formatter

或者你可以试试我的格式化程序。它不是免费的。这是一个命令行工具,它可以结合地对地导弹作为外部工具....Tidycode t - sql格式化程序