SQL Formatter & Beautifier
Paste minified or messy SQL and get properly indented, readable output. Handles subqueries, CASE/WHEN blocks and CTEs. Minify for production. 10 dialects supported.
What This Formatter Actually Does
Most simple online SQL formatters use find-and-replace on keywords — which breaks on anything complex. This tool uses a token-based approach: it reads the SQL character by character, identifies every token (keywords, strings, identifiers, operators, comments), then rebuilds the query with proper structure. Subqueries inside parentheses get their own indentation level. CASE/WHEN/THEN/ELSE/END blocks are indented correctly. GROUP BY and ORDER BY are treated as two-word units, not split across lines.
Formatting Options
- Keyword case — UPPERCASE is the SQL standard convention and easiest to read. Lowercase keywords are preferred in some teams (particularly PostgreSQL shops). "Keep original" leaves your case decisions intact.
- Indent size — 2 spaces is compact and fits more on screen. 4 spaces is the traditional SQL convention and easier to scan visually.
- Comma position — "Comma after" (col1, col2) is the JavaScript convention but harder to comment out a column. "Comma before" (, col1, col2) is preferred by many SQL developers because commenting out the last column never breaks the syntax.
- Remove comments — strips both -- line comments and /* block comments */ from the output. Useful when pasting query plans or sharing SQL without internal notes.
Minify
The Minify button compresses the SQL to a single line with minimal whitespace — useful when embedding SQL strings in application code, config files, or API payloads where line breaks would cause issues. The Remove Comments checkbox works with minify too.