piapia123
en

SQL Formatter & Minifier

Format

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
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, and unquoted identifiers are preserved. Quoted identifiers are re-quoted for the selected dialect (ANSI / Postgres use double quotes, MySQL backticks, SQL Server square brackets), while string literals in single quotes are never touched — they may well contain a backtick or a bracket. 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

  • The output is syntax-highlighted, with keywords, strings and comments colour-coded
  • 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; unquoted identifiers are always preserved
  • Choose a dialect (ANSI / PostgreSQL / MySQL / SQL Server) to re-quote identifiers in that dialect, converting all three quote styles with correct escaping; string literals are left alone
  • Optionally prefix every line with a right-aligned line number (width follows the line count); minify ignores it
  • 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; set the dialect and line numbers if you need them
  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, and what does the dialect option change?
The formatting itself (line breaks, indentation, keyword case) is genuinely dialect agnostic — keywords are case-insensitive, so changing their case alters nothing. What is bound to a dialect is how identifiers are quoted: ANSI and Postgres use double quotes `"name"` (in Postgres a double quote marks an identifier while a single quote marks a string), MySQL uses backticks, and SQL Server square brackets `[name]`. The dialect option therefore converts the quoted identifiers in your input into the chosen dialect, converting `` `order` `` / `[order]` / `"order"` between the three and escaping correctly for each (backticks doubled in MySQL, `]` doubled in SQL Server, `"` doubled in ANSI). String literals in single quotes are never touched — they may contain a backtick or a bracket, and changing them would change your data. Dialect-specific keyword differences are not rewritten, because that would change meaning and is beyond formatting.
Is my SQL uploaded anywhere?
No. Everything runs in your browser memory, the page makes no network requests, and it works offline.

Related tools