SQL Formatter
Paste a messy or one-line SQL query and get it neatly indented, with keywords in the case you prefer, for MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery and more.
Formatted in your browser; your queries are never uploaded.
This SQL formatter turns a query copied from a log, an ORM or a colleague's message into readable, consistently indented SQL. Each clause starts on its own line, columns and conditions are listed one per line, and joins and subqueries are indented, so you can see the structure of a query at a glance and spot a missing condition. It understands the syntax of 16 databases, including MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery and Snowflake.
Before and After
select u.id, u.name, count(o.id) orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id, u.name order by orders desc;
SELECT u.id, u.name, COUNT(o.id) orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = 1 GROUP BY u.id, u.name ORDER BY orders DESC;
Dialect Differences the Formatter Knows
| Database | Quoted names | Other syntax |
|---|---|---|
| MySQL / MariaDB | `order` | # comments, @variables, LIMIT |
| PostgreSQL | "Order" | $1 parameters, :: casts, ->> JSON operators, $$ function bodies |
| SQL Server (T-SQL) | [Order] | TOP, @variables, GO batch separators |
| Oracle PL/SQL | "ORDER" | :name bind variables, BEGIN โฆ END blocks |
| BigQuery | `project.dataset.table` | STRUCT, ARRAY, @params |
SQL Style Tips
- One clause per line (SELECT, FROM, WHERE, GROUP BY, ORDER BY) makes long queries easy to scan and gives cleaner diffs in code review.
- Name your joins clearly. Short aliases such as
ofor orders are fine; aliases liket1andt2make the formatted query harder to follow. - Put AND and OR at the start of the line, as this formatter does, so each condition can be read, commented out or removed on its own.
- Format before you compare. To see what changed between two versions of a query, format both the same way and compare them in the diff checker.
Related Tools
Format the JSON a query returns with the JSON formatter, turn query results saved as CSV into JSON with CSV to JSON, or test a pattern for a REGEXP condition in the regex tester.
Frequently Asked Questions
How do I format a SQL query?
Paste the query, or open a .sql file, and the formatted version appears on the right as you type. Pick your database under SQL dialect, choose upper or lower case keywords and the indentation, then copy the result or download it as a .sql file. Several statements separated by semicolons are formatted one after another.
Why does it say it cannot format my SQL?
Usually because the query uses syntax of a specific database while Standard SQL is selected: backtick `names` and # comments are MySQL, [names] and @variables are SQL Server, $1 placeholders and :: casts are PostgreSQL. Choose the matching dialect. An unclosed quote or bracket also stops the formatter, and the message points to the line and column where it got stuck.
Does formatting change what the query does?
No. Only spaces, line breaks and the letter case of keywords change. Table and column names, string values and comments stay exactly as written. Keyword case does not matter to databases, so SELECT and select run the same.
Should SQL keywords be uppercase?
It is a convention, not a rule. Uppercase keywords (SELECT, FROM, WHERE) make them stand out from table and column names, which is why most style guides and documentation use them. Some teams prefer lowercase for easier typing. Pick one style per project and keep to it.
What does Minify do?
It puts the query on one line: comments are removed and every run of spaces and line breaks becomes a single space, while text inside quotes stays unchanged. That is handy for pasting SQL into code, a log search or a JSON config. MySQL-style # comments are removed only when a MySQL-family dialect is selected, since # is an operator in PostgreSQL.
Is it safe to paste production queries?
Yes. The formatter runs in your browser, so queries, table names and any values in them never leave your device. Very large files are formatted in a background thread so the page stays responsive.