SQL Formatter
Paste an ugly SQL query and get back a cleanly indented, properly capitalised version. The formatter is hand-rolled — no libraries — and recognises SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP and the rest of the standard vocabulary.
How to use
- 1
Paste your SQL
Drop a raw query — single line, copy-pasted from a log, generated by an ORM — into the left-hand editor.
- 2
Pick indent and case
Choose 2 or 4 spaces (or tab) for indentation and whether keywords should be UPPERCASED, lowercased, or kept as-typed.
- 3
Toggle newline-per-clause
When on (default), each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT) starts on its own line. Turn it off for a denser one-line-per-statement layout.
- 4
Format and copy
Click Format SQL. The beautified query appears on the right; copy it or download as query.sql.
Common use cases
- Make an ORM-generated query readable before pasting it into a code review.
- Standardise keyword casing and indentation across a team's SQL files.
- Re-indent a minified query extracted from a log or a DB statement trace.
- Teach SQL by example — feed a messy query in, show the clean version out.
Limitations
- The formatter is structural, not semantic — it does not validate your SQL or catch syntax errors.
- Dialect-specific syntax (PL/pgSQL
$$blocks$$, T-SQL@@IDENTITY, MySQL:=assignment) is tokenised but not specially pretty-printed. - Inputs larger than 1 MB are rejected to keep the tab responsive.
- Subquery indentation is heuristic: parentheses immediately followed by
SELECTorWITHare treated as subqueries; function-call parentheses stay inline.