Skip to content

SQL Formatter

Formats SQL with configurable keyword case, indentation and comma placement, across major dialects.

Lays out a SQL query so you can read it — keywords aligned, clauses on their own lines, joins indented under the table they hang off. It knows five dialects, because the difference between them is mostly in how strings, identifiers and comments are quoted, and getting that wrong is how a formatter mangles a query.

🔒 Runs entirely in your browsersqlformatdatabasebeautify
Dialect

ANSI quoting: double-quoted identifiers, and a quote inside a string written twice.

Keywords
Indent
Commas
Width

SQL in

Drop a .sql file

Read in this tab. Nothing is uploaded.

Formatted

In

253 byte

Out

0 byte

Statements

0

Tokens preserved

yes

This lays out SQL; it does not validate it. A query with a missing FROM will be formatted neatly and still rejected by your database.

How to use it

  1. Pick your dialect first

    MySQL backticks, PostgreSQL dollar quoting, SQL Server brackets — each changes what counts as an identifier and what counts as a string. Standard is the ANSI reading and is right for anything portable.

  2. Set the house style

    Keyword case, indent width, leading or trailing commas, and the width at which a select list wraps. Leading commas look strange until you have git-blamed a column list.

  3. Check "tokens preserved"

    The output is re-tokenised and compared to the input after every run. If it says no, the formatter has misread something — almost always a dialect mismatch — and you should use your input, not its output.

Common questions

Does it validate my query?

No. It lays SQL out; it does not know your schema and does not parse for meaning. A query missing its `FROM` clause will be formatted neatly and rejected by your database exactly as before.

Why were my `--` comments turned into `/* */`?

Only when minifying. A `--` comment runs to the end of its line, so putting the query on one line would comment out everything after it. The page counts how many were converted so the change is not silent.

What does "unterminated string" mean here?

A quote that never closes, usually because the dialect is wrong — a backtick in Standard mode, or a `$$` block in MySQL mode. Everything after it is read as part of that string, which is why the rest of the output looks scrambled.

Can I paste a whole migration file?

Yes — statements are split on semicolons and the count is shown. The formatting runs in a worker, so a large file does not lock the page, though a very long one will take a moment.

Feed it from

Next

These accept what this tool produces, so the result can go straight in.