Paste a one-line or messy SQL statement and get it laid out with each major clause (SELECT, FROM, JOIN, WHERE, ORDER BY and so on) on its own line. Choose 2-space, 4-space or tab indentation and upper-case, lower-case or preserved keywords, or switch to Minify to collapse a query to a single line.
The formatter works on the text only. It does not connect to a database, run the query or check it against a schema.
How to use it
- Paste your query into the Raw SQL box.
- Choose Format SQL or Minify SQL, the indent size and the keyword case.
- Press Copy SQL to take the result.
Worked example
Format SQL mode, 2 spaces, UPPERCASE keywords.
Input
select id,name from users u left join orders o on o.user_id=u.id where u.active=1 and o.total>100 order by name
Result
SELECT id, name
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.active = 1 AND o.total > 100
ORDER BY name
Common mistakes and gotchas
- String literals and quoted identifiers are left alone, so keyword case-changing never alters your data. An unterminated quote is passed through as written.
- Minify removes comments as well as whitespace. Keep your original if the comments matter.
- The formatter is generic rather than dialect-specific. Very vendor-specific syntax is still laid out, but line breaks may not match what a dialect-aware tool would choose.
- Formatting is cosmetic; it does not fix a syntax error. A query that fails in your database will fail the same way after formatting.
Frequently asked questions
Does it change what the query does?
No. Only whitespace, line breaks and the letter case of keywords change.
Can I paste several statements?
Yes. Statements separated by semicolons are formatted one after another.
Is my SQL sent to a server?
No. The formatting runs in your browser; nothing is uploaded or executed.