⬡
SQL FormatterFormat · Syntax highlight · Minify
All tools run in your browser · Free to use

SQL Formatter

SQL generated by ORMs, copied from logs or written in a hurry often ends up as a single long line that is difficult to review. The SQL Formatter breaks the query onto separate lines, one clause per line, so the SELECT list, JOINs, WHERE conditions and GROUP BY clauses are easy to scan.

It is useful for code reviews, debugging slow queries, documenting reports and tidying queries before committing them.

How to use

  1. Paste your SQL into the editor.
  2. Click Format SQL to put each clause (SELECT, FROM, JOIN, WHERE, GROUP BY…) on its own line.
  3. Use ↑ Upper or ↓ Lower to change the case of the query.
  4. Click Minify to collapse it back onto one line.
  5. Turn on Auto to re-format as you type, and use the download button to save a .sql file.

Example

This one-liner:

select u.id, u.name, count(o.id) as orders from users u left join orders o on u.id = o.user_id where u.status = 'active' group by u.id, u.name order by orders desc;

is formatted so each clause starts on its own line, making it obvious which tables are joined and what the query filters and groups by.

SQL style tips

  • Write keywords in uppercase and identifiers in lowercase — it makes the structure of a query stand out.
  • Put each selected column on its own line so diffs show exactly which column changed.
  • Use short, meaningful table aliases (u for users, o for orders) and use them consistently.

Frequently asked questions

Which SQL dialects are supported?
The formatter works on standard SQL keywords, so it handles everyday queries for MySQL, PostgreSQL, SQL Server, SQLite and Oracle.
Does formatting change what my query does?
No. Only whitespace changes. Note that Upper/Lower change the case of the whole query, including string literals, so review the result if your query compares case-sensitive values.

Privacy

This tool runs entirely in your browser. The data you paste or open is processed locally and is never uploaded to or stored on our servers.

Related tools