SQL Formatter
Take a 500-character query written as one unbroken line and lay it out so you can actually see what it does.
How it works
A compact workflow from input to download.
Paste your query
Drop in a SELECT, INSERT, UPDATE or anything else — including the monstrous ones with six joins.
Format it
Keywords are aligned and clauses are placed on their own lines so the shape of the query becomes visible.
Copy it back
Copy the formatted SQL into your editor, migration file or documentation.
Frequently asked questions
Does formatting change what the query does?
Why are keywords conventionally uppercase?
Will it make my query faster?
Is my data sent to a server?
Formatting is how you review a query
SQL has an unusual property among languages: a single statement can be arbitrarily large and arbitrarily complex, and it is still, syntactically, one statement. A reporting query with six joins, three subqueries, a window function and a dozen conditions is one expression that must be understood as a whole. Written as an unbroken line it is essentially unreviewable — you cannot see which condition belongs to which join, or whether that OR is grouped the way its author intended. Formatting puts each clause on its own line and indents subqueries inside their parents, which makes the query's shape visible. Most SQL bugs are structural — a condition in the wrong clause, a join that should have been a left join, missing parentheses around an OR — and structure is exactly what formatting reveals.
The join condition that quietly becomes a filter
Here is a bug that formatting catches and unformatted SQL hides. In a LEFT JOIN, a condition placed in the ON clause filters which rows are joined, while the same condition placed in the WHERE clause filters the final result — and because unmatched rows have NULL in the joined columns, a WHERE condition on those columns silently discards them, turning your left join into an inner join. The query runs perfectly, returns plausible-looking data, and is wrong. Written on one line, the two versions look nearly identical. Formatted, with ON and WHERE on separate lines and their conditions indented beneath them, the difference is immediately visible. That is the case for formatting in one example: it does not find bugs for you, but it stops them from hiding.
Related tools
Continue the workflow with adjacent tools.