What the SQL formatter does
A query copied from a log or an ORM is often one long line. This tool lays it out so you can read it: each major clause starts on its own line, joins are separated, conditions are indented under WHERE, and the select list is broken across lines. You can also minify the SQL back to a single line.
Formatting changes only whitespace and the case of keywords. String values, comments and names are left as you wrote them, so the query means exactly the same thing. It runs in your browser.
How to use it
- Paste your SQL.
- Choose Format or Minify, a 2 or 4 space indent, and whether keywords become uppercase.
- Copy the result.
Example
A one-line query before and after:
select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 and u.created_at > '2025-01-01' group by u.id, u.name having count(o.id) > 3 order by orders desc limit 10;
→
SELECT u.id,
u.name,
count(o.id) AS orders
FROM users u
LEFT JOIN orders o
ON o.user_id = u.id
WHERE u.active = 1
AND u.created_at > '2025-01-01'
GROUP BY u.id,
u.name
HAVING count(o.id) > 3
ORDER BY orders DESC
LIMIT 10;Why format SQL
- Readable queries are easier to review and debug, and mistakes such as a missing join condition stand out.
- Consistent layout makes diffs in version control much smaller.
- Uppercase keywords make the structure visible at a glance.
Limits
SQL has many dialects, and this formatter uses a general layout that works for common SELECT, INSERT, UPDATE and DELETE statements. Very vendor-specific syntax may be laid out plainly. Always run the formatted query to confirm it behaves the same.
Related tools
- Code Beautifier & Formatter: Format JavaScript, TypeScript, JSON, CSS, SCSS, HTML, Markdown and YAML with the Prettier engine.
- Diff Checker: Compare two blocks of text and instantly see line-by-line additions, deletions, and unchanged content.
- JSON Formatter & Validator: Format, validate, and beautify JSON with clear error messages for developers.
- String Escape & Unescape Tool: Escape or unescape text for JSON, JavaScript, HTML, XML, SQL, CSV and regular expressions.
