Developer ToolsA little help for every day

Search by name or task, such as JSON or percentage.

Developer Tools

SQL Formatter and Beautifier

Format SQL with each clause on its own line and indented joins, subqueries and CASE blocks, or minify it to one line. Strings and comments stay untouched.

View all tools
ResultUpdates as you type
SELECT
  u.id,
  u.name,
  count(o.id) AS orders,
  coalesce(sum(o.amount), 0) AS total
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
    AND o.status IN ('paid', 'shipped')
WHERE
  u.created_at BETWEEN '2026-01-01' AND '2026-06-30'
  AND u.city = 'London, UK'
GROUP BY
  u.id,
  u.name
HAVING
  count(o.id) > 2
ORDER BY
  total DESC
LIMIT 20;

1 statement. Strings, quoted identifiers and comments are left untouched, and commas inside function calls do not break lines.

How to use SQL Formatter and Beautifier

Paste one or more SQL statements, choose Format or Minify to one line, and set the keyword case and indent. The formatted query updates as you type, with a statement count and warnings for unclosed quotes or brackets.

  1. Paste your SQLPaste a query from logs, an ORM or a migration; several statements separated by semicolons are handled.
  2. Choose action and casePick Format (beautify) or Minify to one line, then upper case, lower case or Keep as typed for keywords.
  3. Set the indent and copyChoose 2 spaces, 4 spaces or a tab for formatted output, then copy the result.

How queries are laid out

Each main clause (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT and so on) starts a new line and its contents are indented beneath it. Lists in SELECT, GROUP BY, ORDER BY, SET and VALUES get one item per line. AND and OR in WHERE, HAVING and JOIN … ON conditions start new lines, but the AND in BETWEEN 1 AND 5 stays where it is. Brackets that contain a SELECT are laid out as an indented subquery, CASE expressions put each WHEN and ELSE on its own line, and function calls such as coalesce(sum(o.amount), 0) or an OVER (PARTITION BY …) window stay on one line.

What is never changed

Single-quoted strings (including '' escapes), double-quoted, backtick and [bracketed] identifiers, PostgreSQL $$ dollar-quoted strings and both -- and /* */ comments are kept exactly as written, so a value like 'London, UK' is never split at its comma. Keyword case only affects SQL keywords; table, column and function names keep their original case. The formatter adjusts layout only and does not check that the SQL is valid for MySQL, PostgreSQL, SQL Server or SQLite. Minify joins everything onto one line and drops comments along the way.

Accuracy and data handling

Validate the result with your project's own tests and runtime rules before using it in production. The calculation runs in your current browser; the tool code does not send the input to a processing API.

Often Used Together

Next step

FAQ

Which SQL dialects does it support?

The rules are dialect-neutral and cope with MySQL backticks, SQL Server [brackets], PostgreSQL :: casts and $1 parameters, and SQLite. It formats only and does not validate syntax.

Can formatting change what my query does?

No. Only whitespace, line breaks and keyword case change. Strings, identifiers and comments stay exactly as they were, except that minifying removes comments.

Why do I get an unclosed quote warning?

A string is missing its closing quote, so everything after it is treated as part of the string. Check that single quotes are paired and write a quote inside a string as two quotes ('').

More Developer Tools

Related tools