Database & SQL

SQL Formatter

Paste a query to beautify it for Standard SQL, PostgreSQL, MySQL, SQLite or SQL Server. Indentation, keyword case and comma style update the output as you type — and your SQL never leaves the page.

Runs in your browser v1.0.0

Options

live

SQL input

paste or type

One statement or many — separate statements with ;. Strings and comments are preserved exactly as written.

Formatted SQL

live


                

How it works

The query is tokenised in this tab, then re-emitted with clause keywords on their own lines, indented lists and consistent spacing. The dialect option controls how quoted identifiers, backticks, brackets and # comments are recognised. String literals, quoted identifiers and comments are copied through verbatim, so nothing is rewritten or sent anywhere.

Practical uses

Re-indent SQL for several dialects with configurable keyword case, indentation width, and comma placement.

Common ways to use it

  • Make a single-line query readable before reviewing or sharing it.
  • Normalise keyword casing across a batch of queries.
  • Lay out joins, subqueries, CASE expressions, and INSERT value lists consistently.

Format a SELECT with WHERE and ORDER BY

Input

select id, name, email from users where active = 1 and role = 'admin' order by name asc

Output

SELECT
  id,
  name,
  email
FROM users
WHERE active = 1
  AND role = 'admin'
ORDER BY
  name ASC

Defaults: Standard SQL, upper-case keywords, two-space indentation, trailing commas. The tool reports 1 statement, 1 input line changed to 9 output lines, and 6 keywords.

Options that matter

  • Dialect — Standard SQL, PostgreSQL, MySQL, SQLite, or SQL Server; it controls how quoted identifiers, backticks, brackets and # comments are recognised.
  • Keyword case — UPPERCASE, lowercase, or preserve the original spelling.
  • Indentation — two spaces, four spaces, or a tab.
  • Comma style — trailing (a, b) or leading (, b) for wrapped lists.

Things to keep in mind

  • It is a tokenizer and re-emitter, not a full SQL parser or linter, and an unrecognised dialect falls back to Standard SQL.
  • Unterminated string literals, unterminated block comments, and unbalanced parentheses are reported as errors and no output is produced.
  • String literals, quoted identifiers, and comments are copied through verbatim, so keyword case does not change their contents.
  • Formatting runs locally in the browser; the query is not sent anywhere.