SQL Formatter & Minifier
FormatEverything runs locally in your browser — nothing is uploaded
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
- Paste your SQL into the input box
- Choose the mode, indentation and keyword case; set the dialect and line numbers if you need them
- Press Ctrl/⌘ + Enter or click Run
- 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
JSON to Code
FormatTurn JSON into TypeScript interfaces, Go structs, Java classes or Rust structs, with missing keys marked optional. Runs locally in your browser.
Mock Data
GeneratorsDescribe your fields once and get realistic mock records, exportable as JSON, CSV, TSV, SQL, XML, YAML or TOML. All generated in your browser.
Text Cleaner
TextClean up a column pasted out of a log or spreadsheet: deduplicate, sort, drop blank lines, trim whitespace and strip line numbers, all in your browser.
JSON Formatter
FormatFormat, validate and minify JSON in a collapsible tree with syntax highlighting and line numbers. Search, edit, delete or convert to Python dicts.
JSON5 Converter
FormatParse JSON5 into strict JSON: comments, unquoted keys, single quotes, trailing commas, hex and Infinity all work, with errors located by line.
XML Formatter
FormatFormat XML online by tag level, with comments, CDATA and DOCTYPE on their own lines and attribute values left untouched. Runs locally in your browser.