SQL Formatter

Format and beautify SQL for PostgreSQL, MySQL, SQL Server and more.

Result

SELECT
  u.id,
  u.name,
  count(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.active = 1
  AND o.total > 10
GROUP BY
  u.id,
  u.name
HAVING
  count(o.id) > 2
ORDER BY
  orders DESC
LIMIT
  20;
19 lines · 230 bytes

What does a SQL formatter do?

SQL is easy to write on one line and hard to read there. A formatter puts each clause on its own line, indents the columns and conditions and gives keywords a consistent case, so the structure of the query is visible.

The tool reads the query with the rules of the dialect you choose, because databases differ in quoting, functions and keywords. The sample query, about 195 characters on one line, becomes lines for SELECT, FROM with the LEFT JOIN, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT.

How to use the SQL Formatter

  1. Paste your SQL on the left.
  2. Choose your dialect, such as PostgreSQL or MySQL.
  3. Choose keyword case and the indent.
  4. Copy or download the formatted query.

Real situations

When people use the SQL Formatter

  • 1

    Read a query from a log

    ORMs and slow query logs often show SQL on one line. Format it to see the joins and conditions.

  • 2

    Review a pull request

    Format a query before pasting it into a review so the reader can follow it.

  • 3

    Match a team style

    Choose upper or lower case keywords and 2 spaces, 4 spaces or tabs to match your codebase.

  • 4

    Spot a syntax slip

    An unclosed quote or bracket shows up as an error, with a hint to check the dialect.

Good to know

  • Pick the dialect you use, so special syntax is understood.
  • Keep a formatted copy in version control to make changes easy to compare.

FAQ

SQL Formatter: questions answered

Does formatting change what the query does?

No. Only whitespace and the case of keywords change. Names, strings and values are untouched. Still, run important queries through your usual review, and test them before you run them on live data.

Which SQL dialects are supported?

Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake, Amazon Redshift, Spark SQL and Trino or Presto.

Why does the formatter show an error?

The SQL could not be read. Common causes are an unclosed quote or bracket, or syntax from a different dialect. For select * from t where a = 'x it reports a parse error. Check the quotes, or pick your dialect.

Should keywords be upper or lower case?

It is a style choice. Upper case is a long-standing habit that makes keywords stand out, while lower case is also common today. Pick what your team uses, or As written to leave them alone.

Can it format several queries at once?

Yes. Queries separated by semicolons are formatted one after another with blank lines between them.

Can it fix a wrong query?

No. It changes layout only. It will not fix logic mistakes, wrong column names or missing joins. It can help you spot them, because a clear layout is easier to review.

Is this SQL Formatter free and private?

Yes. It is free with no sign-in, and every calculation runs inside your browser. Nothing you type is sent to a server or stored, and the page keeps working offline once it has loaded.

Private by design. No accounts, no cookies, no tracking. Everything you type stays on your device.

How we keep it that way