SQL Formatter

Turn one-line query soup into readable SQL — dialect-aware formatting with your preferred keyword case and indentation.

Why format SQL at all?

SQL is one of the few languages routinely written by machines and debugged by humans. ORMs, query builders and log aggregators emit queries as a single line with erratic casing — fine for the database, hopeless for the person trying to work out why the query is slow. Formatting restores the structure your eye needs: each clause (SELECT, FROM, WHERE, GROUP BY) on its own line, joins and conditions indented beneath it, subqueries visually nested. The classic workflow this tool serves: copy a query out of a slow-query log or APM trace, paste it here, and actually read it before reaching for EXPLAIN ANALYZE.

Why the dialect setting matters

SQL is a standard the way English is a language — every database speaks its own variant. PostgreSQL has :: casts, dollar-quoted strings and ILIKE; MySQL and MariaDB use backtick-quoted identifiers; BigQuery allows hyphens in project-qualified table names; SQLite is famously permissive. A formatter has to tokenise your query before it can lay it out, and tokenising correctly means knowing the dialect — otherwise a $$body$$ string or backticked column gets split mid-token and mangled. Pick your database from the dropdown and the parser follows its rules. If you get an error on valid SQL, a dialect mismatch is the most common cause.

FAQ

Uppercase or lowercase keywords — which is correct?

Neither, functionally: SQL keywords are case-insensitive in every mainstream database. Uppercase keywords are the traditional convention and make clauses easy to spot in embedded strings; lowercase is increasingly popular in codebases that treat SQL like any other code. This tool supports both, plus "preserve" to leave your casing untouched — pick the one your team's style guide mandates.

Does formatting change what the query does?

No. Formatting only rearranges whitespace and (optionally) keyword casing — string literals, identifiers, numbers and comments are preserved verbatim, and the statement the database executes is semantically identical.

Can I paste queries containing production data?

The formatter runs entirely in your browser — nothing you paste is transmitted or stored. Still, log-extracted queries often embed literal customer values in WHERE clauses, so apply the same care you would with any sensitive text.

Built by Abasthan Cloud

Free tools are just the start

Deploy your next app on bare-metal cloud with per-second billing — your first app is free, no credit card required.