← All tools/Minifiers/Code/SQL Formatter
SQL Formatter
Paste a messy SQL query and get a clean, readable version — keywords in capitals, one clause per line.
Nothing leaves your browser — the formatting happens on this page. The query is reformatted as you type, and the button re-runs it.
Formatted SQL
How it works
1. Collapse extra spaces. 2. Upper-case keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, AND, OR …). 3. Start a new line before each major clause. 4. Put AND / OR and each item after a comma on its own indented line.
Worked example: “select id, name from users where age > 18 order by name” becomes:
SELECT id,
name
FROM users
WHERE age > 18
ORDER BY name
— four clauses, each on its own line, with the two selected columns listed one per line.
Frequently asked questions
Does it change what my query does?
No. Formatting only changes spacing, line breaks and the capitalisation of keywords. Table names, column names, values and the order of clauses are left exactly as you wrote them.
Which SQL dialects does it handle?
The formatter works on standard SQL — SELECT, INSERT, UPDATE and DELETE with the usual clauses. It does not check your query against a database, so a query with a syntax error is still formatted, not fixed.
Why is each column on its own line?
Long column lists are much easier to scan one per line, and adding or removing a column becomes a one-line change. The same idea applies to AND and OR conditions.
Does my SQL leave my browser?
No. The formatting runs entirely in JavaScript on this page, and nothing is uploaded or stored anywhere.
Can it format a query with a subquery?
Yes — subqueries are formatted with the same rules. A subquery inside a FROM or WHERE clause gets its own indented SELECT line, so the nesting stays visible.
Tell us what you think
Loving this tool, or stuck on something? Tell us — it takes a minute.
We’ll only use your name and email to reply if needed. The tool and page are filled in for you.