SQL Formatter & Beautifier Online

Paste mangled SQL, get readable SQL. Keywords capitalized, clauses on their own lines, parentheses indented — all locally in your browser.

Embed this tool on your website / blog No code required · Copy and paste
HTML Embed Code (iframe):
<iframe src="https://lucentool.com/sql-formatter" width="100%" height="650" style="border:1px solid #e5e0d8;border-radius:12px;max-width:850px;width:100%;" frameborder="0"></iframe>
<div style="font-size:12px;color:#78716c;margin-top:6px;font-family:sans-serif;">Powered by <a href="https://lucentool.com/sql-formatter" target="_blank" style="color:#c85a32;text-decoration:none;">Lucentool - SQL Formatter & Beautifier Online</a></div>

What this formatter does

It tokenizes your SQL and rebuilds it with consistent rules: clause keywords (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, JOIN, ON, SET, VALUES…) start new indented lines; commas and operators get spacing; strings and comments are preserved untouched; parentheses increase indentation.

What it doesn't do

Formatting conventions

Clause-first style: each main clause on its own line at the same level, sub-queries indented one level, AND/OR aligned under their WHERE. This matches the style used in most open-source projects and is easy to read in diffs.

Example — input: select u.id,u.name from users u where u.active=true order by u.id becomes:

SELECT u.id,
       u.name
FROM users u
WHERE u.active = true
ORDER BY u.id;

How the conversion runs

format() is a keyword-and-state machine rather than a parser: it breaks the line before major clauses (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY), indents by nesting level, and flush() emits the result. Quote and comment state is tracked so a keyword inside a string literal is left alone. Because it never builds a syntax tree, it cannot change what the statement means — it only moves whitespace around.

Edge cases and hard limits

It does not validate SQL: a broken statement gets formatted just as cheerfully as a correct one. Dialect-specific quoting — backticks, double quotes, square brackets — is handled generically, so MySQL and PostgreSQL oddities may need a manual touch. Deeply nested subqueries produce very long indented lines, and extremely long statements format slowly because the whole text is processed at once.

Privacy: processed in your browser

The statement is reformatted as text in this tab. It is not sent to any database, not executed, and no connection string leaves the page.

Frequently asked questions

Will formatting change what the query does?

No. Only whitespace and line breaks change; keywords, identifiers and literals are untouched.

Does it support different dialects?

It uses generic rules. Dialect-specific syntax will not be broken, but the layout is not tuned per database.

Can I run the formatted query directly?

Yes, the semantics are unchanged — though running it against production without a test is a separate decision.