在SQL Server Management Studio中格式化SQL [英] Format SQL in SQL Server Management Studio

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

问题描述

在Visual Studio&在其他IDE中,您可以通过键盘快捷键,菜单或键入时轻松地自动设置代码格式.

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

我想知道是否还有办法在SQL Server Management Studio中启用此标准功能?

I was wondering if there is yet a way to enable this standard feature in SQL Server Management Studio?

我正在处理一些大型存储过程,这些过程杂乱地处理了格式不正确的SQL,如果我可以直接选择全选->格式化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"

推荐答案

最新答案,但希望是值得的:穷人的T-SQL格式化程序是一种开源(免费)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版" (它处于beta版已经有几个月了,刚刚获得了对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 - K Ctrl - 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 :)

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

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