SQL formatter

Paste a query to lay it out one clause per line with consistent indentation and keyword case. Choose your database so its own syntax is understood.

  • 100% free
  • Runs in your browser
  • No uploads
Keywords
Indent

How to format SQL

  1. Paste your SQL or open a .sql file. Several statements separated by semicolons are fine.
  2. Pick the dialect. Standard SQL works for most queries; choose your database for its own syntax.
  3. Choose keyword case and indent. UPPER, lower or as typed; 2 or 4 spaces, tabs, or Minify for one line.
  4. Copy or download. Download saves a .sql file.

Before and after

A query copied from a log or an ORM usually arrives on one line:

select o.id, c.name from orders o join customers c on c.id = o.customer_id where o.status = 'paid' and o.total > 100 order by o.created_at desc

Formatted with upper-case keywords and 2 spaces, each clause starts a line and each column and condition is indented:

SELECT
  o.id,
  c.name
FROM
  orders o
  JOIN customers c ON c.id = o.customer_id
WHERE
  o.status = 'paid'
  AND o.total > 100
ORDER BY
  o.created_at DESC

SQL style conventions

ConventionWhy
Keywords in upper caseSELECT, FROM and WHERE stand out from table and column names
One clause per lineEach part of the query is easy to find, and diffs show exactly what changed
One column per lineAdding or removing a column changes one line in version control
AND / OR at the start of the lineConditions line up and can be commented out one at a time
Short table aliaseso for orders, c for customers keeps joins readable

Tips

  • Comparing two versions of a query? Format both with the same settings first, then paste them into the diff checker so only real changes show up.
  • Keep comments useful. -- line comments and /* block */ comments are kept when formatting and removed only by Minify.
  • Stored procedures. Very long procedural code (loops, IF blocks, DECLARE sections) is formatted statement by statement; check the result reads the way your team expects before committing it.

Frequently asked questions

Which SQL dialects are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL, DuckDB and Trino or Presto. Choosing the right one matters for syntax only that database has, such as backtick identifiers in MySQL, :: casts in PostgreSQL or square brackets in SQL Server.

Does formatting change what my query does?

No. Only spaces, line breaks and the case of keywords change. Table and column names, string values and comments stay as written. Keyword case doesn't matter to SQL databases, so SELECT and select run the same.

Why do I get an error for a query that runs fine?

Usually the dialect is wrong: a MySQL-only or PostgreSQL-only feature can't be read as Standard SQL. Pick your database from the Dialect list. Placeholders like ? and $1 and template variables such as {{name}} may also need the dialect that uses them.

Is my SQL sent to a server?

No. The formatter is loaded into this page the first time you use it and runs in your browser, so queries containing table names, customer data or credentials stay on your device.

What does Minify do?

It puts the query on one line: comments are removed and runs of spaces and line breaks become a single space. Text inside quotes, backticks, square brackets and PostgreSQL $$ blocks is never touched.