SQL formatter
Readable SQL queries
Settings
SQL query
Result
Paste a SQL query to format it.
About this tool
The SQL formatter cleans up a query written on one line, copied from a log or generated by an ORM, so you can read it, discuss it in a code review or paste it into documentation. It supports 13 dialects: standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), BigQuery, Oracle (PL/SQL), Snowflake, Redshift, Spark SQL, Trino / Presto and IBM Db2.
You choose the keyword case (uppercase, lowercase or unchanged), indentation with 2 or 4 spaces or a tab, and the number of blank lines between multiple queries. Minify mode does the opposite: it strips whitespace and comments onto a single line while leaving strings and quoted identifiers untouched. When a query cannot be parsed, the error shows the line and column.
How to use it
- Pick the "Format" or "Minify" action.
- Select your database "Dialect", then set "Keyword case", "Indentation" and "Lines between queries".
- Paste your code into the "SQL query" field, or click "Example" to try it out.
- Grab the "Result" with "Copy" or "Download" (a query.sql file).
Frequently asked questions
Why does the dialect matter?
Each database has its own syntax: MySQL backticks, SQL Server square brackets, PostgreSQL-specific operators. With the right dialect, these are recognized and the query is split correctly. With the wrong one, formatting may fail, and the tool then shows the line and column of the problem.
What does Minify do exactly?
It collapses the query onto a single line by removing extra whitespace and comments (--, /* */, and # for MySQL, MariaDB and BigQuery). The contents of strings and quoted identifiers are kept exactly as written.
Can I format several queries at once?
Yes. Paste several statements separated by semicolons: they are formatted one after another, with 0 to 3 blank lines between them depending on the "Lines between queries" setting. Comments are kept in Format mode.
Is my query sent to a server?
No. Formatting uses the sql-formatter library loaded into the page, and minification runs in local code, so the query stays in your browser. Only your settings are remembered for your next visit, never the text you pasted.