SQL Formatter
Format a SQL query with clause keywords on their own lines and consistent indentation, making long queries readable.
Everything you type here is processed on your own device. No input is sent to a server, logged, or stored.
What the SQL Formatter does
The SQL formatter on this page will format a SQL query with clause keywords on their own lines and consistent indentation, making long queries readable. Paste your text in, pick the options you need, and copy the result straight back out. It is most often used for making a long query from an ORM log readable. More utilities in this area are collected on FreeToolsWorld.org.
How to use it
- Paste a single SQL statement.
- Choose how keywords should be cased.
- Major clauses move to their own lines and conditions are indented.
- Copy the formatted query.
How it works
The formatter recognises the major clause keywords and places each on its own line, indenting AND, OR and ON so that join and filter conditions sit visually beneath the clause they belong to. Select lists are broken at commas.
This is a text formatter, not a SQL parser. It does not validate syntax, understand dialect differences, or reformat subqueries with their own nesting level. Keywords appearing inside a string literal or a column name may be moved onto a new line incorrectly — check the output before running anything.
Formatting matters more than it seems for review: a query whose clauses are visible at a glance is much easier to reason about than the same query on one line, and most SQL bugs are in a WHERE clause nobody could see.
When to use it
- Making a long query from an ORM log readable.
- Tidying SQL before committing it to version control.
- Preparing a query for a code review or documentation.
Common mistakes to avoid
- Running formatted output without checking it, when a keyword inside a string literal may have been split.
- Expecting dialect-aware formatting — this is generic and does not know your database.
Frequently asked questions
Does it validate my SQL?
No. It only reformats text and will happily format a query with syntax errors. Run it against your database to check correctness.
Will it break a query containing the word "from" in a string?
It might split the line there, since it matches keywords textually rather than parsing the statement. Review the output when your query contains keyword-like words inside literals.