How to use SQL Formatter
What it does & when you need it
You've inherited a query that arrives as one long line — a SELECT with three joins, a tangle of conditions, and no line breaks in sight — and you need to actually read it before you dare touch it. This tool pretty-prints SQL: it inserts consistent indentation and line breaks so clauses, joins, and predicates stack up where your eye expects them. Paste a query pulled from an ORM log, a stored procedure, or a copy-pasted one-liner from a coworker, pick the dialect it was written for, and get back something you can review, diff, or paste into a migration. Everything runs in your browser, so a query that embeds table names, schema details, or literal values from production never leaves your machine.
How to use
- Paste your statement into the input.sql buffer, press Sample to load an
example multi-join SELECT, or Upload a
.sqlfile. - Choose the Dialect that matches where the query runs — Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, BigQuery, or SQL Server (T-SQL). Toggle Uppercase keywords on or off to match your team's house style.
- The formatted output updates as you type. Press Format or
Ctrl/Cmd+Enterto copy the result, or use the Copy button on the output buffer.
Things worth knowing
Formatting is purely cosmetic. Reformatting only rearranges whitespace and line breaks — it never rewrites your logic, reorders clauses, or changes which rows come back. A minified one-liner and its pretty-printed version are the same statement to the database engine; the only audience for the extra spacing is the humans reading the code. That also means it's safe to run on a query you don't fully understand yet: you get readability without altering behavior.
The dialect you pick genuinely matters. SQL is a family of dialects, not one
language, and they disagree on syntax the formatter has to respect. Identifier quoting
is the classic trap: MySQL and MariaDB wrap identifiers in backticks (`user`),
while PostgreSQL, SQLite, and the ANSI standard use double quotes ("user"), and SQL
Server uses square brackets. Row-limiting differs too — Postgres and MySQL use
LIMIT, whereas SQL Server historically reaches for TOP. Choosing the wrong dialect
can make the formatter mishandle a quoted name or a dialect-specific keyword, so match
it to your actual database.
Uppercasing keywords is a widely followed convention. Rendering reserved words like
SELECT, FROM, WHERE, and JOIN in uppercase while leaving your table and column
names in their original case makes the skeleton of a query pop out at a glance — you
can trace the clause structure without reading every token. It carries no meaning to
the engine (SQL keywords are case-insensitive), but as a readability habit it's close
to universal in style guides, which is why the toggle defaults to on.
Formatting is not sanitizing. Making a query readable does nothing to make it safe. Never assemble SQL by concatenating user input into a string — that's exactly how SQL injection happens. Use parameterized queries or prepared statements and let the driver bind values separately from the statement text. Treat this tool as a formatter for queries you already trust, not a cleaning step for untrusted input.
Once your SQL reads cleanly, you might format a JSON payload returned by the same service, tidy the JavaScript that builds the query, or turn a CSV export into JSON for a seed script.