SQL Formatter

Format messy SQL with the open-source sql-formatter engine: pick your dialect, keyword casing and indent style.

Formatting happens locally in your browser. Your queries never leave your device.

Indent
Formatted SQL
—

How It Works

Formatting is done by sql-formatter, the same open-source (MIT) library this page bundles from npm. It runs in three steps: a dialect-specific tokenizer splits your query into keywords, identifiers, strings and operators; a lightweight parse pass infers clause structure (what is a SELECT list, what is nested inside a CASE); and a layout writer re-emits the tokens one clause per block with your indent and casing. No database is involved at any point.

Tokenizer, not validator
Because the engine works on tokens, it formats anything that can be split into SQL tokens — including half-finished queries you are typing. It will not tell you that a table does not exist or that a JOIN is logically wrong; syntax only gets checked as far as tokenizing requires. The library also cannot handle stored procedures or custom statement delimiters, and those cases raise a visible error instead of a mangled result.
The five dialects here (and there are more)
This page offers SQL standard, MySQL, PostgreSQL, SQLite and BigQuery — the engines most people paste queries from. The underlying library additionally knows ClickHouse, DB2, Hive, MariaDB, N1QL, Oracle PL/SQL, Redshift, Snowflake, Spark, Transact-SQL, Trino and others; dialect choice affects token rules (backticks, ::casts, @params), which is why formatting with the wrong one can look slightly off.
Why UPPERCASE keywords are the default
SQL is case-insensitive for keywords, so style is the only signal separating SELECT oops from an intended identifier. The uppercase-keywords convention (clauses shout, data stays as typed) is the dominant house style in books, linters and team guides, and it makes query structure scannable at a glance. Choose lowercase or preserve if your team standard differs — the tool obeys.

Frequently Asked Questions

Does this tool run my SQL anywhere?

No — it never touches a database. The formatter reads your query as plain text, rewrites whitespace and keyword casing, and shows you the result. Your statements, table names and data stay on your device, and there is no connection to configure or attempt.

Is there a minify or single-line option?

Not on this page. The underlying sql-formatter library (v15, same as npm's current release) is a pretty-printer: it lays queries out, it does not compress them. Older versions had a minified mode; it was removed upstream. For shrinking minified-on-purpose statements, our Code Minifier tool covers SQL-adjacent text as a separate job.

Will it tell me if my SQL is wrong?

Only incidentally. sql-formatter is a tokenizer plus layout engine, not a validator: it does not check your schema, function names or even full grammar compliance, and most malformed-but-tokenizable text still formats. It does fail on genuinely unterminated constructs (like an unclosed string literal), and that error is surfaced in the error line.

Why do the results differ between dialects for the same query?

Each dialect ships its own keyword list and token rules, so the same text can be segmented differently: BigQuery treats struct literals and @params specially, PostgreSQL knows ::casts, MySQL accepts backtick identifiers. Pick your actual engine before formatting — casing and line breaks follow the dialect's tokenizer.

Is anything uploaded to a server?

No. The formatter is a JavaScript module bundled with this page and running in your browser (sql-formatter, MIT licensed). Your queries never leave your device — which matters, because queries often contain credentials and customer data.