SQL Formatter

Paste a raw or minified query and get readable, indented SQL with clause-per-line layout and your choice of keyword casing. Works with common SQL dialects.

Runs entirely in your browser — nothing is sent to our servers.

How to use it
  1. Paste your SQL query into the left panel.
  2. Choose whether keywords should be uppercased, lowercased, or left as-is.
  3. Pick an indent width of two or four spaces.
  4. Press Format to beautify, or Minify to collapse the query onto one line.
  5. Press Copy to grab the result, or Clear to reset both panels.

Query

Formatted

Click Format or Minify to see the result here.

What is SQL formatting?

SQL formatting rewrites a query's whitespace so its structure becomes visible. Each major clause — SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY — starts on its own line, the expressions beneath it are indented, and boolean conditions line up underneath the clause they belong to. The query itself is unchanged; only the layout differs.

This matters most for queries you did not write: an ORM-generated statement pulled from a slow-query log, a one-line query copied out of application code, or a report someone emailed you. Reading a 400-character single line to find the join condition is slow and error-prone. Formatted, the same query can be scanned in seconds.

Keyword casing is the other half of readability. Most teams standardise on uppercase keywords with lowercase identifiers so the language and your schema are visually distinct. This tool lets you apply either convention, or leave casing exactly as you typed it.

Why use this SQL formatter

It is fully client-side. Queries often contain table names, column names and literal values that reveal a lot about a production system, so the safest formatter is one that never transmits the query at all. Nothing you paste here leaves your browser.

It is dialect-agnostic by design. Rather than parsing to a specific dialect's grammar, it works on a token level, so Postgres, MySQL, SQLite, SQL Server and BigQuery queries all format sensibly — including comments and string literals, which are left untouched (see the quoting note below for one SQL Server-specific exception).

And it stays out of your way: no account, no query size cap, no ads crowding the editor.

What formatting does and doesn't touch

Comments and string literals stay untouched

Comments and string literals are left exactly as written — a token-level formatter that reflowed the contents of a string literal (say, one containing the word SELECT) would silently corrupt the query, so both are treated as opaque and passed through untouched no matter what whitespace or keywords they contain internally.

CTEs, UNIONs and window functions

Multi-line constructs get sensible defaults without needing to be told about them specifically. A query with a CTE indents the parenthesized SELECT inside WITH name AS (...) one level deeper than the line that opens it, and a multi-branch UNION or UNION ALL puts each branch on its own line at the same indent so the columns line up for comparison. Window functions and their OVER (...) clauses aren't given special line-breaking yet — they format on one line, which stays readable for a short PARTITION BY but is worth reviewing by eye once the clause gets long.

Dialect-specific quoting (including SQL Server brackets)

Because formatting works at the token level instead of parsing a specific dialect's full grammar, single-, double- and backtick-quoted strings and identifiers — covering Postgres and MySQL quoting — are treated as opaque and preserved exactly as written, so the same formatter works sensibly across dialects without picking one upfront. SQL Server's [bracketed] identifiers aren't recognized as quoted text the same way, so double-check a bracket-heavy SQL Server query's output before relying on it.

SQL formatter FAQ

No. Formatting happens locally in your browser, so table names, column names and literals never leave your device.

The formatter is dialect-agnostic and works on tokens rather than a dialect grammar, so Postgres, MySQL, SQLite, SQL Server, Oracle and BigQuery queries all format well.

No. Only whitespace and, if you choose, keyword capitalisation change. String literals, single/double/backtick-quoted identifiers and comments are preserved verbatim. SQL Server's [bracketed] identifiers aren't recognized as quoted text the same way, so review a bracket-heavy query's output before relying on it.

Yes. Statements separated by semicolons are each formatted and kept in order.

Not yet — an OVER (...) clause formats on one line rather than breaking PARTITION BY and ORDER BY onto their own lines. Short window clauses stay readable; long ones are worth reviewing by eye.

No. It is a formatter, not a parser or linter — an invalid query will still be re-indented rather than rejected.

Line comments starting with -- are preserved on their own line at the current indent level.

Putting each boolean condition on its own indented line makes it obvious which conditions belong to the same clause, especially in long filters.

No hard limit. Very large scripts are formatted in the browser, so extremely long input may take a moment.