SQL Formatter
Paste a messy SQL query and get a clean, readable version back in one click. This free online SQL formatter uppercases keywords, puts each clause on its own line, and indents the rest — so you can actually read the query you wrote last month.
Regex-based formatting: uppercases major keywords, puts each clause on its own line, and indents continuation lines. It does not parse SQL, so it cannot validate your query or catch syntax errors — always test formatted SQL before running it. Everything runs in your browser; your SQL never leaves your device.
What Is a SQL Formatter?
A SQL formatter — sometimes called a SQL beautifier — takes a SQL query written on one long line (or with inconsistent spacing) and rewrites its layout so the structure is easy to follow. It changes whitespace and capitalisation only; it does not change what the query does.
A query like select id, name from users where age > 18 order by name becomes:
SELECT id, name FROM users WHERE age > 18 ORDER BY name
The keywords stand out, each clause starts on its own line, and the shape of the query is visible at a glance.
How to Use This SQL Formatter
- Paste your SQL query into the top box — or click “Load sample query” to see an example.
- Click Format SQL.
- Review the formatted output in the lower box.
- Click Copy output to paste it into your editor, documentation, or pull request.
What Gets Formatted
- Keywords are uppercased — SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOIN, ON, AND, OR, INSERT, UPDATE, DELETE, and more.
- Each major clause starts on a new line — SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, JOINs, and others.
- Continuation lines are indented — AND/OR conditions and the extra columns in a SELECT list sit two spaces in, so the clause structure stays clear.
- SELECT lists are split — each selected column goes on its own line (commas inside function calls like COUNT(*) are left alone).
- Text inside quotes is left untouched — string values such as ‘active’ are never uppercased or re-spaced.
What it does not do: it does not parse SQL, so it cannot validate your query, catch syntax errors, or guarantee the output will run. Always test formatted SQL before running it against a real database.
Frequently Asked Questions
A SQL formatter rearranges a query's whitespace and capitalisation to make it readable — uppercase keywords, one clause per line, indented continuations. It does not change what the query returns.
Yes. It is free, needs no signup, and runs entirely in your browser — your SQL is never uploaded or stored.
No. Formatting only changes whitespace and keyword capitalisation. String values in quotes are left exactly as written. That said, always test a formatted query before running it on a live database.
Yes. INSERT INTO, VALUES, UPDATE, SET, and DELETE FROM are all recognised as clause starters and placed on their own lines, just like SELECT queries.
No. This is a regex-based formatter, not a SQL parser. It cannot tell you whether a query is valid or catch syntax errors — use your database or a dedicated SQL validator for that.
The formatting rules are generic — standard keywords and clause structure shared by MySQL, PostgreSQL, SQL Server, and SQLite — so it works for everyday queries in any of them.
Working with text instead of SQL? Try our word counter. Browse more tools in Text Tools.