SQL formatter and beautifier
Beautify SQL for Postgres, MySQL, T-SQL, Oracle, SQLite, Snowflake and BigQuery. Runs in your browser, so production queries stay on your machine.
- Runs in your browser
- Files are never uploaded
- Free, no account
Adds ILIKE, RETURNING, ON CONFLICT, dollar-quoted bodies and :: casts.
Your SQL never leaves this tab — check it yourself—
Starting the network probe…
The counter above wraps fetch, XMLHttpRequest and navigator.sendBeacon in this tab and counts every call. It does not block anything — it just reports.
Two ways to verify independently
- Turn off Wi-Fi or enable airplane mode, then use the tool. It keeps working, because the page is already fully loaded.
- Open your browser devtools, switch to the Network tab, clear it, and run the tool. No new row appears.
Why this matters
In 2025 researchers found that popular online formatters had retained tens of thousands of user-submitted snippets — JSONFormatter.org and CodeBeautify together exposed roughly 80,000 saved documents, many containing live cloud credentials, private keys and internal database connection strings, because “format this” quietly meant “upload this”. A separate incident exposed roughly 3.5 million user PDFs on a document-conversion service. The only structural fix is not sending the data in the first place: this site is served under a Content-Security-Policy whose connect-src contains no third-party origin, so a request off this device cannot be made even by accident.
How to format a SQL query
- Paste the query, or use Load .sql file for something too big to paste comfortably.
- Pick the dialect you actually run. It selects the keyword list, the comment syntax and the identifier quoting.
- Choose the keyword case and indent width. The output pane updates on every keystroke.
- Copy the result, download it as
.sql, or press Replace input with result and keep editing.
What the formatter does, precisely
It moves whitespace. That is the entire contract, and it is worth stating plainly because
several popular formatters do more: they rewrite != to <>,
strip the AS from aliases, or reflow a CASE expression into a shape
that is legal but no longer matches your team’s review diff. This one tokenizes the input,
decides where the line breaks and indentation go, and reprints every token exactly as you
wrote it.
The layout rules it applies:
- Top-level clauses —
SELECT,FROM,WHERE,GROUP BY,HAVING,ORDER BY,LIMIT— start at the left edge of their statement. - Joins get their own line, with
ONkept on the same line so the join condition reads as one thought. - AND and OR begin a continuation line indented one step, so a five-condition
WHEREreads as a list rather than a paragraph. - Select-list columns go one per line, which is what makes a diff show a single added column rather than a whole rewritten line.
- Subqueries open a new indent level; function-call parentheses do not, so
coalesce(a, b)stays on one line whileIN (SELECT …)breaks. - CASE puts each
WHENand theELSEon its own line and alignsENDwith theCASE.
Why formatting SQL on someone else’s server is a bad idea
A query is rarely just syntax. It carries your schema — table names, column names, the shape of
your data model — and very often a literal: an account ID, an email address, a date range that
identifies a customer. Some queries carry more than that. Connection strings, credentials
embedded in a COPY or FDW statement, and internal hostnames all end up
pasted into formatters every day.
In 2025, security researchers enumerated the public “saved snippet” URLs of several popular formatting sites and recovered roughly 80,000 documents, a meaningful fraction of which contained live cloud keys and database connection strings. None of those users intended to publish anything; they clicked Format. The structural fix is not a better privacy policy, it is not sending the text at all. Open the panel under the tool and watch the request counter stay at zero, or disconnect from the network and keep working.
Dialect differences that actually change the output
| Dialect | Identifier quoting | Notable keywords |
|---|---|---|
| PostgreSQL | "double quotes" | ILIKE, RETURNING, ON CONFLICT, dollar-quoted bodies, :: casts |
| MySQL / MariaDB | `backticks` | ON DUPLICATE KEY UPDATE, STRAIGHT_JOIN, # comments, backslash escapes in strings |
| SQL Server | [brackets] | TOP, OUTPUT, MERGE, APPLY, @variables |
| Oracle | "double quotes" | CONNECT BY, START WITH, MINUS, DUAL |
| SQLite | Any of the above | PRAGMA, AUTOINCREMENT, upsert syntax |
| Snowflake / BigQuery | Double quotes / backticks | QUALIFY, UNNEST, LATERAL FLATTEN |
Keeping a team’s SQL consistent
Formatting is only worth doing if it is done the same way every time. Agree on three things and write them down: keyword case, indent width, and whether select-list columns go one per line. Uppercase keywords with a two-space indent and one column per line is the most common convention in analytics teams, largely because it produces the smallest diffs. Then format before review, not after — a reviewer who has to mentally reformat a query is not reading it.
Questions
Does the formatter change my query?
No. It only moves whitespace. The tokenizer reads strings, comments, quoted identifiers and parameters as single units and reprints them byte for byte — no keyword is reordered, no alias is renamed, nothing is added or removed. If a query cannot be laid out, the tool says so and leaves your input untouched rather than emitting something mangled.
Is it safe to paste a query with real table and column names?
Yes, and that is the point. The formatting runs as JavaScript inside your tab; there is no upload step and no logging. In 2025 researchers found roughly 80,000 saved snippets on popular formatter sites, many containing live database credentials and connection strings — that can only happen on a site that receives your paste. This one does not.
Which dialect should I pick?
Pick the one you actually run. The dialect selects the keyword list, the comment syntax (MySQL also accepts #), the identifier quoting (backticks in MySQL and BigQuery, square brackets in T-SQL, double quotes elsewhere) and dialect-specific keywords such as QUALIFY, RETURNING and CONNECT BY. Choosing the wrong one still formats, it just may not uppercase every keyword.
Can it handle a file with many statements?
Yes. Statements are separated on the semicolon, the indent stack resets between them, and you can put a blank line between each one. Load a .sql file with the button rather than pasting if it is large.
Why are my parentheses reported as unbalanced?
The formatter counts opening and closing parentheses before it lays anything out. If they do not match it still produces output, but it warns you, because the indentation past that point is a guess. It is usually a missing bracket in a subquery or a CASE expression.