SQL Formatter / Beautifier
Paste a one-line query from a log file, an ORM's debug output, or a colleague's Slack message, and get it back as readable SQL: one clause per line, subqueries indented by nesting depth, JOIN conditions under their JOIN, and AND/OR at the start of each condition line. The formatter tokenizes your SQL properly — strings, comments, and quoted identifiers pass through byte-for-byte untouched, so a semicolon inside a string literal will never split your query. Everything runs live in your browser; no query ever leaves the page.
Standard SQL quotes identifiers with double quotes: "column name".
Paste a query above (or load the example) — formatting happens live as you type, entirely in your browser. Strings, comments, and semicolons inside quotes are preserved exactly.
How to use the sql formatter / beautifier
- Paste your SQL (or click “Load example”) — formatting happens live as you type.
- Choose keyword casing: UPPERCASE (the most common convention), lowercase, or leave the original casing untouched.
- Pick indent width (2 spaces, 4 spaces, or tabs) and comma style — trailing commas at line ends or leading commas at line starts.
- Tick “Minify instead” to collapse the query to a single line for log greps or embedding in code.
- Copy the result. Multiple statements separated by top-level semicolons are formatted independently with a blank line between them.
The conventions this formatter applies
- One clause per line. SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, and set operators (UNION, EXCEPT, INTERSECT) each start a new line at the current nesting level, so the query's skeleton is scannable down the left margin.
- JOINs on their own line, ON indented. Each JOIN reads as a unit: the table on the JOIN line, the join condition indented one level beneath it. Extra predicates chained with AND stay aligned under the ON.
- Select lists break above 3 items. Short lists like SELECT id, name stay on one line; anything longer gets one column per line, which makes column additions show up as one-line diffs in code review.
- AND/OR start the line. Leading boolean operators make it impossible to misread which conditions combine — and the single AND inside BETWEEN x AND y is correctly kept inline.
- Subqueries indent by parenthesis depth. A derived table or IN (SELECT …) opens onto a new indented block with its closing parenthesis back at the parent level.
Leading vs trailing commas — the honest version
Trailing commas (the default here) read like prose and match what every other programming language does; their weakness is that deleting the last select-list item leaves a dangling comma one line up. Leading commas put the comma at the start of the next line, so any item except the first can be added, removed, or commented out without touching its neighbors — at the cost of a look that many people find ugly and that no major style guide outside the data world endorses. Teams that live in ad-hoc analytics queries (where commenting out columns is constant) often prefer leading; application codebases overwhelmingly use trailing. Both are one toggle away here — pick whichever your team already uses, because consistency beats either convention.
Why format before code review
Unformatted SQL hides logic bugs that formatted SQL exposes. The classic example: WHERE a = 1 OR b = 2 AND c = 3 — AND binds tighter than OR, so this means a = 1 OR (b = 2 AND c = 3), not (a = 1 OR b = 2) AND c = 3. With each condition on its own line, the missing parentheses jump out. Formatting also normalizes diffs: if everyone formats with the same settings, a pull request that touches one column shows a one-line change instead of a rewrapped 40-line blob, and reviewers review logic instead of whitespace.
Frequently asked questions
Does this formatter change what my query does?
No. It only moves whitespace and (optionally) changes keyword casing — keywords are case-insensitive in every major SQL dialect. String literals, quoted identifiers, numbers, and comments are passed through exactly as written. The tokenizer treats '…' and "…" contents as opaque, so a semicolon or the word SELECT inside a string is never touched.
Should SQL keywords be uppercase or lowercase?
Functionally it makes no difference — SELECT, select, and SeLeCt are identical to the engine. UPPERCASE keywords are the older, still-dominant convention because they visually separate structure from identifiers in editors without syntax highlighting. Lowercase has grown popular in dbt and analytics teams since modern editors color keywords anyway. Choose one per codebase and enforce it; this tool supports both plus leave-as-is.
Can it format multiple statements at once?
Yes. Statements are split at top-level semicolons — semicolons inside string literals or comments are correctly ignored — and each statement is formatted independently with a blank line between them, so you can paste an entire migration script.
Which SQL dialects are supported?
The formatter is dialect-agnostic by design: it formats structure (clauses, joins, parentheses, commas), which is identical across MySQL, PostgreSQL, SQL Server, SQLite, and BigQuery. The dialect selector adjusts the identifier-quoting hint shown under the options — backticks for MySQL, double quotes for Postgres/standard, square brackets for SQL Server — since that is where dialects genuinely differ in syntax.
What does minify mode do, and when would I use it?
Minify collapses the query to a single line with single spaces, keeping strings and comments intact. It is useful for embedding SQL in JSON or YAML config, grepping logs where queries are logged on one line, and pasting into tools that mangle multi-line input. It is the exact inverse workflow of beautifying: same tokens, different whitespace.
Are my queries uploaded anywhere?
No. Tokenizing and formatting run entirely in your browser tab with no network requests — table names, schema details, and any literal values in your queries stay on your machine. You can confirm by formatting with the network tab open or while offline.
Related tools
- JSON Formatter & ValidatorFormat, validate, and beautify JSON in your browser — instant error messages with line numbers, 2 or 4-space indent, minify mode, and copy.
- HTML Formatter / BeautifierBeautify messy HTML with proper tag-aware indentation or minify it for production — formatted in your browser with one-click copy.
- YAML Validator / LinterValidate YAML in your browser with line-numbered errors — catch indentation mistakes, tabs, and duplicate keys in Kubernetes and CI configs.
- .htpasswd GeneratorGenerate .htpasswd lines for Apache and nginx basic auth — bcrypt or MD5-crypt hashes computed locally, your password never touches a server.
- Aspect Ratio CalculatorCalculate aspect ratios and missing dimensions — lock 16:9 or any ratio and solve width or height for video, images, and responsive design.
- Base64 ⇄ Image ConverterConvert Base64 to an image and images to Base64 data URIs in your browser — instant preview, PNG, JPG, WebP and SVG support, nothing uploaded.