SQL Formatter – Beautify and Indent SQL Queries Online
Paste a one-line or messy SQL query and get it back neatly formatted — clauses on their own lines, columns listed one per line, subqueries indented and keywords in uppercase.
Paste your SQL and it is formatted instantly: SELECT, FROM, WHERE, JOIN, GROUP BY and ORDER BY start new lines, each selected column goes on its own line, AND/OR conditions are indented and subqueries get their own block. Choose 2 spaces, 4 spaces or tabs, and keyword case.
How to use SQL Formatter
- Paste your SQL query.
- Choose the indent size.
- Turn uppercase keywords on or off.
- Read the formatted query.
- Copy it, or click Minify for a single line.
Why format SQL?
SQL generated by applications, ORMs or logs often arrives as one long line. Formatted SQL is easier to read, review and debug: you see at a glance which tables are joined, which filters apply and how results are grouped. Teams that format consistently also get cleaner diffs in version control.
What the formatter does
- Starts major clauses on new lines: SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY, LIMIT, INSERT INTO, VALUES, UPDATE, SET.
- Puts each selected column and each GROUP BY item on its own line.
- Moves AND and OR conditions onto separate, indented lines.
- Indents subqueries inside parentheses as their own block.
- Optionally converts keywords to UPPERCASE while leaving table and column names untouched.
- Never changes text inside quotes or comments.
Before and after
| Before | After |
|---|---|
| select id,name from users where active=1 and age>18 order by name | SELECT / id, / name / FROM users / WHERE active = 1 / AND age > 18 / ORDER BY name |
Style tips
- Uppercase keywords and lowercase identifiers make queries easier to scan.
- Give tables short, meaningful aliases (users u, orders o).
- Prefer explicit JOIN … ON over comma joins in the FROM clause.
- Avoid SELECT * in production code; list the columns you need.
Minify
The Minify button does the opposite: it collapses the query into a single line, useful for embedding SQL in code strings or log messages.
Dialects
The formatter is token-based and works with common syntax from MySQL, MariaDB, PostgreSQL, SQLite and SQL Server. Very dialect-specific constructs are kept as they are. Everything runs in your browser. For JSON results from your database, try the JSON Formatter or export them with JSON to CSV Converter.
Formatting in your workflow
Most teams agree on one style and apply it automatically in their editor or before committing code. Until that is set up, a quick online formatter is the fastest way to make a long query from a log file or an error report readable. Format the query first, then look for missing join conditions, filters on the wrong table or a GROUP BY that does not match the selected columns, which are the most common causes of wrong results.
You may also find these free tools useful: JSON Formatter, Password Generator and Regex Tester.
Frequently asked questions
How do I format a SQL query?
Paste it into the formatter. It is beautified instantly with clauses on new lines and indented conditions.
Does it change my query?
Only whitespace and, if you choose, keyword case. Names, values, strings and comments stay as they are.
Which SQL dialects are supported?
Common syntax from MySQL, MariaDB, PostgreSQL, SQLite and SQL Server.
Can I minify SQL?
Yes. Click Minify to collapse the query into one line.
Is my SQL sent to a server?
No. Formatting runs locally in your browser.
Last updated: