Formatters

Format SQL with uppercase keywords and 2-space indentation

SQL Formatter prints your query back with keywords in uppercase, each clause on its own line, and a two-space indent per nesting level. Developers paste long queries from logs, ORM output and ticket reports into it before debugging or code review. Identifiers, aliases and string literals keep the case and content you typed, and multiple statements separated by semicolons are formatted one after another with a blank line between them. It uses the sql-formatter library with its generic SQL dialect.

How to use SQL Formatter

  1. Open SQL Formatter in the Toolbox101 app.
  2. Paste the query into the SQL box; a copy from application logs or ORM output works well.
  3. Read the Output box: SELECT, FROM, WHERE and other keywords become uppercase, one clause per line.
  4. Joined tables and grouped expressions sit two spaces deep, while column names and literal values keep the case you typed.
  5. Click Copy to put the formatted query on your clipboard.

Worked example

SQL Formatter returns the output below for this input.

Input

select u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where o.status = 'paid' group by u.id having count(o.id) > 1 order by orders desc limit 10;

Output

SELECT
  u.name,
  count(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  o.status = 'paid'
GROUP BY
  u.id
HAVING
  count(o.id) > 1
ORDER BY
  orders DESC
LIMIT
  10;

Check it yourself: open SQL Formatter and enter the same input.

Frequently asked questions

Which SQL dialects does the formatter support?

The page uses the generic SQL parser, so standard SELECT, INSERT, UPDATE, and DELETE statements with joins, grouping, and subqueries format cleanly. Highly dialect-specific syntax can raise a parse error, which appears as an error message in the Output area rather than a guessed layout.

Why are some words uppercased and others not?

Only recognized keywords such as SELECT, FROM, WHERE, and DESC are changed to uppercase. Identifiers, table names, aliases, and function names such as count() keep the case you typed: the example shows u.name and count(o.id) staying lowercase while SELECT and DESC become uppercase.

Does it validate or run my query?

No. Formatting is purely presentational: a query that references a nonexistent table still formats normally because the tool never executes SQL or checks semantics. It only reports parse errors when the syntax itself is not recognized, as an error message in the Output area.

Are SQL comments preserved when formatting?

Yes. Line comments starting with -- and block comments are kept in the formatted output. A comment that sits above a statement stays above it, and the statement's keywords are still uppercased and indented around it, exactly as if the comment were not there.

Use SQL Formatter now

Runs in your browser. Nothing you type is uploaded.