SQL formatter
Paste unreadable SQL, get it back readable. The formatting happens in this tab and your SQL is never transmitted anywhere — so a query with real table and column names in it stays on your machine.
Style
Your SQL
Empty
Formatted
Nothing formatted yet
Worth knowing
- It formats, it does not validate. The parser is lenient, so some invalid SQL will be laid out neatly rather than rejected. A clean result is not a syntax check.
- Your SQL is never transmitted. Formatting is JavaScript running in this tab, and nothing here sends the contents of the box anywhere. To be precise about what does happen over the network: the first time you press Format, the browser downloads the formatting engine itself, the same way it downloads a stylesheet. That request carries no part of your query. Once it has loaded, formatting keeps working offline — though if a statement has to be abandoned the engine is reloaded, which offline relies on it still being in the browser cache.
- Client-side does not mean hermetic. A browser extension with permission to read this page could still read what you type — that is true of any web page, and worth knowing if the query is genuinely sensitive.
- Stored procedure bodies come out poorly. The underlying parser does not model
BEGIN/ENDblocks, so procedure andTRY/CATCHbodies are left roughly as they were. Statements are what it is good at. - Table hints are kept inline. The underlying parser reads
WITHas the start of a common table expression, soWITH (NOLOCK)would otherwise be broken onto its own line. The documented hints are recognised and put back exactly as you wrote them; anything unrecognised is left for the parser to lay out, which may not be pretty but will not change what your query means. - There are limits, and they are deliberate: 20,000 characters, plus budgets on the number of tokens, operators and levels of nested parentheses. The parser builds a node per token and its memory use climbs far faster than the length of the statement — a chain of nine thousand additions is only 18 KB and will exhaust half a gigabyte. Nothing is ever truncated: oversized input is refused and told why.
- Formatting runs in a background worker, so the page stays responsive and a statement that ties the parser in knots can be abandoned rather than freezing the tab.
Built on sql-formatter, used under the MIT licence. Full notices are inlicenses.txt.