1. Home
  2. Database
  3. SQL Formatter

SQL Formatter

Beautify SQL queries for MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery and more, with your choice of style.

Runs in your browser
Keywords
Indent

Formatted SQL

Waiting for input.
Minify it

What is the SQL Formatter?

Long SQL queries are hard to read on one line or with inconsistent spacing. The SQL Formatter rewrites a query with each clause (SELECT, FROM, JOIN, WHERE, GROUP BY…) on its own line, consistent indentation and keyword casing, so you can review it, spot mistakes and paste it into code or documentation.

Choose your database so its own syntax is understood: MySQL and MariaDB backticks, PostgreSQL casts and dollar-quoted functions, SQL Server brackets, Oracle PL/SQL, BigQuery, Snowflake and more. Formatting only changes whitespace and, if you choose, the case of keywords; your strings, names and logic stay the same.

How to use it

  1. Paste a query, upload a .sql file or click Example.
  2. Choose your database (dialect).
  3. Pick keyword case, indentation and how many lines between statements.
  4. Copy the formatted SQL or download it.

Example

Input
select o.id, c.name, sum(oi.qty*oi.price) total from orders o join customers c on c.id=o.customer_id join order_items oi on oi.order_id=o.id where o.created_at >= '2026-01-01' group by o.id, c.name order by total desc limit 10;
Output
SELECT
  o.id,
  c.name,
  sum(oi.qty * oi.price) total
FROM
  orders o
  JOIN customers c ON c.id = o.customer_id
  JOIN order_items oi ON oi.order_id = o.id
WHERE
  o.created_at >= '2026-01-01'
GROUP BY
  o.id,
  c.name
ORDER BY
  total DESC
LIMIT
  10;

Features

  • 20+ dialects. Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark, DuckDB, ClickHouse and more.
  • Your style. UPPER, lower or unchanged keywords; 2 or 4 spaces or tabs; standard or tabular indentation.
  • Many statements. Formats whole scripts, with blank lines between statements.
  • Safe. Only whitespace and keyword case change; strings and identifiers are left exactly as written.
  • Highlighted output. Keywords, strings, numbers and comments in colour so the structure stands out.
  • Private. Your queries are formatted in your browser and never uploaded.

Frequently asked questions

Will formatting change what my query does?

No. The formatter only changes whitespace, line breaks and (if you choose) the case of keywords and functions. Strings, identifiers and the order of everything stay the same.

Why does formatting fail on my query?

Usually the dialect is wrong: for example backtick names need MySQL, MariaDB or BigQuery, and [bracketed] names need SQL Server. Pick the dialect your database uses and try again. Unclosed quotes also stop it.

Should SQL keywords be upper case?

It is a style choice, not a rule; databases accept either. Upper-case keywords are traditional and make the structure easy to scan; lower case is popular in modern codebases. Pick one and use it consistently.

Can I minify SQL instead?

Yes, use the SQL Minifier to remove comments and put a query on one line, for example to embed it in code or a config file.

Last updated · Free, no sign-up, runs in your browser.

Free for everyone, kept free by you.

No paywall, no sign-up and no watermarks. If a tool saved you time, you can chip in any amount by UPI to keep Nova Free Tools running.

Esc
↑↓ move↵ openEsc close