Free Online SQL Formatter

Paste a SQL query below and click the dedicated "Format SQL" button in the toolbar to clean up indentation and capitalize keywords consistently.

Input Ready

Input statistics are available via the Stats button above this field.

Output

Output statistics are available via the Stats button above this field.

Results are provided for informational purposes only and may contain errors. Please verify important information independently. Use of this tool is at your own risk.

What the SQL Formatter does

The SQL Formatter rewrites a query with consistent indentation and line breaks and capitalizes keywords. Each clause starts on its own line (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) and the columns or conditions under it are indented by two spaces.

It uses a SQL-aware formatter rather than plain text wrapping, so it understands joins, subqueries, CASE expressions, CTEs and string literals. Identifiers and values are left exactly as written; only spacing and keyword case change.

When to use it

  • Reading a long one-line query copied from an ORM log, a monitoring tool or an error message.
  • Preparing a query for code review, documentation or a pull request, so everyone reads the same layout.
  • Cleaning up SQL before turning INSERT rows into data with the SQL (INSERT Statements) to JSON Converter.
  • Spotting a missing join condition or a misplaced WHERE clause, which is much easier when every clause sits on its own line.

Worked example

Input

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 group by u.id, u.name order by orders desc;

Output

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
GROUP BY
  u.id,
  u.name
ORDER BY
  orders DESC;

Common questions about the SQL Formatter

How do I format a query?

Paste the SQL into the input box and click the Format SQL button in the toolbar. The formatted query replaces the input, ready to copy.

Which SQL dialects work?

Standard SQL formats correctly for MySQL, PostgreSQL, SQL Server, SQLite and Oracle in everyday queries. Vendor-specific syntax is kept as written, even when it is not reformatted.

Does formatting change what the query does?

No. Only whitespace and the case of SQL keywords change. Table names, column names, string values and comments stay exactly the same, so the query returns the same result.

Frequently Asked Questions

Does this work for INSERT statements too?

Yes - and if you’re working with INSERT statements specifically, see also the SQL to JSON and JSON to SQL converters.

Is this tool free?

Yes, it's free to use. No signup, no email required. Get results on this page.

How do I get my result?

Use the tool on this page. Your result appears here; no email delivery is required.