SQL Formatter & Beautifier

Paste a messy query and get clean, consistently indented SQL. Supports 17 dialects, keyword casing and a one-click minifier, all in your browser.

Runs in your browserNo sign-upNothing uploaded

Formatted SQL

How to use the SQL Formatter

  1. Paste one or more SQL statements into the input box, or open a .sql file.
  2. Choose your database dialect so its syntax, such as :: casts, [brackets], backticks or $$ strings, is parsed correctly.
  3. Set keyword case (UPPER, lower or preserve), indentation and the number of blank lines between statements.
  4. Switch to Minify to strip comments and whitespace for logs, ORMs or URL parameters.
  5. Copy the result or download it as a .sql file.

Why format SQL?

Queries copied from ORM logs, query plans or application code usually arrive as one long line. Putting each clause (SELECT, FROM, JOIN, WHERE, GROUP BY) on its own line and indenting columns and conditions makes the logic readable. It also makes code review diffs smaller and helps you spot a missing join condition or a misplaced OR.

SQL style conventions

  • Uppercase keywords (SELECT, WHERE) separate SQL syntax from table and column names. Most style guides recommend this, though lowercase is popular in dbt and analytics teams.
  • One column per line makes adding or removing columns a one-line diff.
  • Consistent indentation (2 or 4 spaces) inside clauses and subqueries shows the nesting at a glance.
  • Statement terminators: end every statement with ; so multi-statement scripts are unambiguous.

Supported SQL dialects

Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server (T-SQL), Oracle PL/SQL, Google BigQuery, Snowflake, Amazon Redshift, Spark SQL, Trino/Presto, Hive, IBM Db2, Couchbase N1QL, SingleStore and TiDB. If a query fails to parse, try a more specific dialect: @variables, $1 parameters and vendor-specific operators are only recognised in their own dialect.

What the minifier does

Minify mode removes --, # and /* */ comments, collapses whitespace and line breaks into single spaces, and drops spaces around commas and parentheses. String literals and quoted identifiers ('…', "…", `…`, […], $$…$$) are copied byte-for-byte, so the query's meaning never changes.

Frequently asked questions

Is my SQL sent to a server?
No. Formatting uses the open-source sql-formatter library running in your browser. Queries that contain table names, customer data or credentials stay on your machine.
Does formatting change what the query does?
No. Only whitespace, line breaks and (if you choose) keyword case change. Identifiers, string literals and comments are kept as written.
Why do I get a parse error on valid SQL?
The query probably uses syntax specific to another database. Select the matching dialect, for example PostgreSQL for ::type casts or SQL Server for [bracketed] names and @params.
Can I format several statements at once?
Yes. Separate statements with semicolons. You can choose how many blank lines go between them in the output.
Will keyword case change my column names?
No. Only reserved keywords, data types and built-in functions are re-cased. Table and column names keep their original spelling.

Related tools