SQL Formatter

Format SQL for the dialect you actually use, with keywords cased and clauses indented, entirely in your browser.

SQL
Formatted SQL
Runs locally in your browser

About the SQL Formatter

Queries copied from logs, ORMs and BI tools arrive as one line. This formatter uses the sql-formatter library to lay them out the way a person would write them: each major clause on its own line, joins and conditions indented, keywords in the case you choose, and a blank line between statements. Subqueries, CTEs, window functions and CASE expressions are indented as nested blocks.

Dialect matters because each database has its own keywords, quoting rules and operators. Pick MySQL for backticks and LIMIT, T-SQL for square brackets and TOP, PostgreSQL for :: casts and $1 parameters, BigQuery for backticked project.dataset.table names, and so on. Choosing the wrong dialect usually still formats but may misread an identifier. A query the parser cannot read is reported with the line and column of the problem.

Unlike some online formatters, nothing here is sent to a server, which matters because queries often embed table names, customer identifiers and literal values. To compress a query back into one line, use the SQL Minifier; to turn INSERT statements into data, SQL to JSON.

How to use

  1. Paste the SQL on the left, or upload a .sql file.
  2. Choose your database dialect, the indent, and keyword case.
  3. Copy or download the formatted query. Swap sends it to the minifier.

Common questions

Which databases are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL, Hive, Trino and Db2.
Does it change the meaning of the query?
No. Only whitespace and keyword case change. Identifiers, literals and comments are preserved.
Can it format stored procedures?
Simple procedural blocks format acceptably. Complex T-SQL or PL/SQL control flow may produce odd indentation; format the queries inside separately if needed.
Are comments kept?
Yes. Both -- line comments and /* */ block comments stay in place.