SQL Formatter

Paste a messy SQL query and get a clean, readable version back in one click. This free online SQL formatter uppercases keywords, puts each clause on its own line, and indents the rest — so you can actually read the query you wrote last month.

Regex-based formatting: uppercases major keywords, puts each clause on its own line, and indents continuation lines. It does not parse SQL, so it cannot validate your query or catch syntax errors — always test formatted SQL before running it. Everything runs in your browser; your SQL never leaves your device.

What Is a SQL Formatter?

A SQL formatter — sometimes called a SQL beautifier — takes a SQL query written on one long line (or with inconsistent spacing) and rewrites its layout so the structure is easy to follow. It changes whitespace and capitalisation only; it does not change what the query does.

A query like select id, name from users where age > 18 order by name becomes:

SELECT id,
  name
FROM users
WHERE age > 18
ORDER BY name

The keywords stand out, each clause starts on its own line, and the shape of the query is visible at a glance.

How to Use This SQL Formatter

  1. Paste your SQL query into the top box — or click “Load sample query” to see an example.
  2. Click Format SQL.
  3. Review the formatted output in the lower box.
  4. Click Copy output to paste it into your editor, documentation, or pull request.

What Gets Formatted

  • Keywords are uppercased — SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOIN, ON, AND, OR, INSERT, UPDATE, DELETE, and more.
  • Each major clause starts on a new line — SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, JOINs, and others.
  • Continuation lines are indented — AND/OR conditions and the extra columns in a SELECT list sit two spaces in, so the clause structure stays clear.
  • SELECT lists are split — each selected column goes on its own line (commas inside function calls like COUNT(*) are left alone).
  • Text inside quotes is left untouched — string values such as ‘active’ are never uppercased or re-spaced.

What it does not do: it does not parse SQL, so it cannot validate your query, catch syntax errors, or guarantee the output will run. Always test formatted SQL before running it against a real database.

Frequently Asked Questions

A SQL formatter rearranges a query's whitespace and capitalisation to make it readable — uppercase keywords, one clause per line, indented continuations. It does not change what the query returns.

Working with text instead of SQL? Try our word counter. Browse more tools in Text Tools.