SQL Formatter
Format SQL queries with consistent keyword casing and indentation.
Formatted SQL
Paste a query on the left.
About SQL Formatter
A long query written on one line is almost impossible to review. Putting each major clause on its own line and indenting nested expressions turns the same query into something you can read top to bottom.
This formatter upper-cases keywords, breaks before the major clauses, indents parenthesised subqueries, and leaves your literals and comments untouched.
How SQL Formatter works in your browser
The formatter tokenises your statement and re-indents it around SQL’s structural keywords: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY and the JOIN family each start a new line, and the parenthesis depth of subqueries drives the indentation so nested queries visibly nest.
String literals and quoted identifiers are preserved untouched, so a keyword appearing inside a quoted string is never mistaken for a structural keyword and reformatted.
It is a formatter, not a parser or a linter: it will not tell you that a column does not exist or that a join is missing a condition. It changes only whitespace and keyword casing, so the statement it produces is the statement you gave it.
When to use it
- Making a long generated query — from an ORM or a BI tool — readable enough to review.
- Normalising formatting before committing a migration, so future diffs show logic changes rather than reflowed whitespace.
- Understanding an inherited report query by seeing its subquery structure laid out.
- Formatting a query containing real table names and business logic without sending it to a hosted formatter.
Frequently asked questions
Which SQL dialects are supported?
The formatter is dialect-agnostic. It recognises standard clauses and operators shared by PostgreSQL, MySQL, SQL Server and SQLite.
Will it change my query?
No. Only whitespace and keyword casing change; string literals, identifiers and comments are preserved exactly.
Does it handle subqueries?
Yes. Nested parentheses increase the indentation level, so common table expressions and subqueries stay readable.