SQL Formatter

Format SQL queries in your browser for 15 dialects including PostgreSQL, MySQL and SQL Server, with 2 or 4 space or tab indent and keyword case. Free.

About SQL Formatter

The SQL Formatter turns a long one-line query into clean, indented SQL that is easy to read and review. Works with 15 dialects including PostgreSQL, MySQL and SQL Server.

Pick your dialect

Dialect-specific syntax, such as PostgreSQL's ->> and :: operators, is formatted correctly.

Keyword case

UPPERCASE, lowercase, or keep keywords as you typed them.

Indentation

2 spaces, 4 spaces or tabs.

Safe

The query is never run, only formatted. It does not check table names or rewrite your logic.

Good for

Reviewing queries generated by an ORM, tidying a long query before sharing it, and learning how joins are structured.

Private

Everything runs in your browser. Nothing you paste is uploaded.

SQL style tips

Put each main clause, such as SELECT, FROM, WHERE and GROUP BY, on its own line. In long queries list one column per line and use short, clear table aliases.

How to use SQL Formatter

  1. Paste your SQL or open a file.
  2. Choose the dialect, the indent and the keyword case.
  3. Read the formatted query or the error.
  4. Copy it or download a .sql file.

Help & FAQ

What does the SQL Formatter do?

It rewrites a SQL query with line breaks and indentation, using the dialect, indent and keyword case you choose.

Which dialects are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server, Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark, Hive, Trino, DB2, DuckDB and ClickHouse.

Does it change our keywords?

Only the case, if you ask. You can choose UPPERCASE, lowercase or Keep as typed. Names and strings are not changed.

Will it run or validate our query?

No. It only formats the text. It does not connect to a database or check that tables and columns exist.

What if we see Could not format this SQL?

The parser could not read the text. Check for unbalanced brackets or quotes and try a different dialect, as the message suggests.

Why did our comment move?

In the test a comment after the semicolon was placed on its own line below the statement. The comment is kept but its position can change.

Does it understand PostgreSQL operators?

Yes. In the test ->>, :: casts and $1 parameters were handled and ILIKE was upper-cased.

Can we use tabs for indentation?

Yes. Choose Tab in the Indent list, or two or four spaces.

Does it work for stored procedures?

Oracle PL/SQL and SQL Server modes are offered, but long procedural code is not guaranteed to format perfectly, so check the output.

Does it make a query faster?

No. Formatting changes layout only. The meaning and the speed of the query stay the same.

Can we make the SQL smaller instead?

Yes. The SQL Minifier removes comments and extra spaces.

Is our SQL uploaded?

No. The formatting runs in your browser and the query is not sent to a server.

More in Developer Tools

See all 39 in Developer Tools