Skip to content
M2TOOLKIT

Developer · free tool

SQL Formatter & Query Compare

Format long SQL queries so they're easy to read — or compare two versions of a query to see which clauses changed.

Use it as often as you like — it's free, with no sign-up and no limits.

  • Developer
  • Free
  • No sign-up
  • Runs in your browser
  • Updated
What do you want to do?
Keywords

Paste, type, or drop a file here

Need sample data to run a query against? Turn JSON into tables with JSON to SQL.

Everything you type is processed in your browser. Nothing you enter is sent to our servers or stored by us.

How to use the SQL Formatter

  1. Choose Format a query or Compare two queries.
  2. Pick the SQL dialect, keyword case and indentation.
  3. Paste your SQL (or open a .sql file). For a compact one-line version, tick Compact output.
  4. Copy or download the formatted SQL, or the diff between the two queries.

What does this tool do?

Each clause (SELECT, FROM, JOIN, WHERE, GROUP BY…) starts on its own line, with columns and conditions indented underneath. Formatting uses the open-source sql-formatter library, which parses the dialect you choose — MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, Oracle PL/SQL, BigQuery, Snowflake, Redshift, DuckDB, Spark, Trino, Hive, ClickHouse, Db2, TiDB and SingleStore — and keeps string literals and comments exactly as written. If a query uses syntax the chosen dialect doesn't know, you get the parser's message instead of a mangled query.

Compare mode formats both queries the same way before comparing them, so differences in line breaks, spacing and keyword case disappear and each changed clause shows up as a changed line with the exact words highlighted. It's a text comparison of the SQL: it tells you what was edited, not whether two different queries return the same rows.

Why use it?

  • 18 SQL dialects.
  • Comments and string literals preserved.
  • Compact mode that never breaks -- comments.
  • Clause-by-clause comparison of two queries.

Example

select id,name from users where active=1 order by name becomes
SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
ORDER BY
  name

Comparing it with a version that filters on active = 0 highlights only the 1 → 0 in the WHERE clause.

Accuracy and limits

  • Procedural code (stored procedures, PL/pgSQL blocks) and template placeholders such as {{variable}} may not parse in every dialect.
  • Your queries are formatted and compared in your browser; nothing is sent to a server or run against a database.

Privacy

Everything you type is processed in your browser. Nothing you enter is sent to our servers or stored by us. There's no account to create and nothing to install.

Frequently asked questions

Will formatting change what my query does?

No. Only whitespace, line breaks and (if you choose) keyword case change. String literals, quoted identifiers and comments are kept exactly.

Can it tell me if two queries are equivalent?

No — and be wary of tools that claim to. It shows exactly which parts of the text differ after consistent formatting. Two different queries can still return the same rows, and similar-looking ones can return different rows.

What does compact output do?

It collapses all whitespace outside strings and comments to single spaces, giving a one-line query for logs, code strings or URLs. A -- comment keeps its line break so it can't comment out the rest of the query.

Does it check that my SQL is correct?

It formats the query's structure but doesn't connect to a database, so it can't check that tables or columns exist. A query that formats cleanly can still fail when you run it.

Why does choosing a dialect matter?

Databases differ in syntax, like backticks in MySQL, square brackets in SQL Server, or special operators in PostgreSQL. Choosing your dialect helps the formatter read these correctly.

Last reviewed by the M2Toolkit team.

Other tools people use alongside the sql formatter.