SQL Formatter for SQL Management Studio [closed]
-
03-07-2019 - |
Question
I was wondering if there is a plugin/tool for SQL Server Management Studio that will format your 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"
Solution
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.
OTHER TIPS
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 :)
There is a special trick I discovered by accident.
- Select the query you wish to format.
- Ctrl+Shift+Q (This will open your query in the query designer)
- 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.
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.
This is a free, online one: http://www.sqlinform.com/ (requires Java Runtime Environment)
It is not built in, but it's fast to use it. :) http://www.dpriver.com/pp/sqlformat.htm
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
Edit: Oops - I just noticed they have versions for SSMS, Visual Studio, and a desktop version etc. Haven't tried them personally yet.
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.
SSMS Tools Pack does a good job of formatting and the other tools in the pack come in quite handy
This web site here does basic SQL keyword capitalisation:
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