piapia123
en

SQL Formatter & Minifier

Formatting

Everything runs locally in your browser — nothing is uploaded

Input
Output

Expand a statement that was squeezed onto one line into a clause-per-line structure: each clause starts its own line with the body indented under it, AND / OR and JOIN / ON break onto their own lines, and a subquery inside parentheses is indented one level deeper with its closing parenthesis returned to the outer level. Keywords can be upper case, lower case or left exactly as written, while identifiers and anything quoted are never touched. String literals, comments, backtick and bracket identifiers and Postgres dollar quoting are all excluded from the structural scan, so a semicolon inside 'a;b' never cuts a statement in half.

Features

  • One line per clause: SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, VALUES, SET, RETURNING and friends
  • AND / OR / JOIN / ON each start a line, so long condition lists keep a visible boundary
  • Subqueries in parentheses open a block and their closing parenthesis returns to the clause body level
  • Function call parentheses stay inline, so COUNT(*) is never split apart
  • Keywords can be upper case, lower case or kept as written; identifiers and strings are always preserved
  • String literals, comments, backtick and bracket identifiers and Postgres dollar quoting are excluded from the structural scan
  • Minify removes comments and redundant whitespace without gluing - -1 into --1, which would comment out the rest of the line
  • No syntax validation: malformed SQL is indented as best it can rather than rejected

How to use

  1. Paste your SQL into the input box
  2. Choose the mode, indentation and keyword case
  3. Press Ctrl/⌘ + Enter or click Run
  4. Click Copy to take the result

FAQ

Does it validate SQL syntax?
No. It only rearranges whitespace and keyword case, so a statement with a typo is formatted just the same. Treat it as a way to make working queries readable, not as a replacement for your database error messages.
Why does minify remove comments as well?
A line comment collapsed onto a single line comments out everything after it, while the output still looks perfectly normal. Dropping comments is safer than leaving a trap in the statement. Use format mode when you need to keep them.
Which SQL dialects are supported?
The keyword list covers common SQL, with allowances for MySQL # comments and backticks, SQL Server bracket identifiers, and Postgres dollar quoting and :: casts. The formatting itself is dialect agnostic.
Is my SQL uploaded anywhere?
No. Everything runs in your browser memory, the page makes no network requests, and it works offline.

Related tools