What SQL formatting is
SQL is free-form: a database does not care whether a query sits on one line or twenty. People do care. A long query on one line, such as one copied from an application log or generated by an ORM, is hard to scan. Formatting breaks the query into lines so each clause starts in the same place, making it easier to see what is selected, from where, and under which conditions.
This tool takes a simple approach. It collapses all whitespace to single spaces and then starts a new line before a fixed list of keywords: SELECT, FROM, WHERE, AND, OR, GROUP BY, ORDER BY, HAVING, LIMIT, the JOIN variants (JOIN, INNER JOIN, LEFT JOIN and RIGHT JOIN), UNION, INSERT INTO, VALUES, UPDATE, SET and DELETE FROM.
When it helps
You might use it when debugging a slow query pulled from a log, reviewing SQL that a teammate pasted into chat, documenting a query, or just making a hand-written one readable before you add to it. Splitting at AND and OR makes it easy to read conditions one at a time, and seeing each JOIN on its own line makes the table relationships clearer.
Queries that mix with other data formats come up too, for example when you export results as JSON and want to pretty-print them with the JSON Formatter.
How to format SQL with this tool
- Paste or type your query into the box labeled SQL query. An example single-line query is already there.
- The Formatted box updates automatically with one clause per line.
- Click Copy to copy the formatted text. There is no download button and no settings for indentation or keyword case.
The text is handled in your browser and is not uploaded. The tool never connects to a database or runs your query.
What it does not do
This is a keyword line-breaker, not a full SQL parser, so it is simpler than a dedicated formatter. Lines are not indented: a column list stays on the SELECT line, and nested subqueries are not indented under their parent, though a SELECT inside a subquery does start a new line.
Keywords that begin a new line are written in uppercase, but other words keep whatever case you typed. A SELECT at the very start of the query is left in its original case, because only keywords preceded by whitespace are matched. For example, a lowercase select at the beginning stays lowercase while the later FROM and WHERE become uppercase.
The tool does not recognize quoted strings or comments. A keyword that appears as a standalone word inside a string literal may cause a line break there, and AND inside a BETWEEN range also starts a new line. Line comments that run to the end of a line will be merged onto the line with the rest of the query, because whitespace is collapsed first, so remove such comments before formatting. Always check the output before running it.