How to Format
SQL Queries
Turn a wall of minified SQL into something readable — in your browser, across 5 dialects, without uploading it anywhere.
How to format SQL queries properly is one of those skills that separates "I can write a SELECT" from "I can debug a 40-line JOIN at 2am." Raw or ORM-generated SQL arrives as a single ugly line with no indentation, and the first thing any experienced developer does is run it through a formatter. This guide covers the safe, free way to do it — including what most online formatters do with your query that you probably didn't realise.
The 10-second version
Open the SQL Formatter. Paste your query. Pick your dialect. Copy the formatted output. The query never leaves your browser.
Why "Online SQL Formatter" Is a Privacy Question
Most online SQL formatters upload your query to their server for processing. That's usually invisible to you — you paste, click Format, get a response — but it means your SQL (including table names, column names, and sometimes literal values from WHERE clauses) has been transmitted to a third party and logged somewhere. For a throwaway SELECT that's fine. For a production query, it's schema disclosure.
This matters more than it sounds. SQL queries reveal a surprising amount about your database schema — the tables you have, how they relate, your naming conventions, and occasionally real IDs or business logic embedded in query literals. A client-side formatter removes this concern entirely by doing the work in your browser.
Step 1 — Open the SQL Formatter
Go to the SQL Formatter. The page loads in your browser — no account, no installation, and no network request is made when you format a query. You can verify this yourself with DevTools → Network tab before pasting.
Step 2 — Paste Your SQL
Drop your SQL into the left input pane. The tool accepts:
.sql migration files..query, SQLAlchemy echo=True, ActiveRecord to_sql, EF Core logs..sql files with several statements separated by semicolons. Each gets formatted independently.Step 3 — Pick Your Dialect
Different SQL dialects format slightly differently — keyword casing, function names, quoted identifier style, and dialect-specific syntax like RETURNING or LIMIT ... OFFSET. Select the dialect that matches your database:
| Dialect | Use when your database is |
|---|---|
| MySQL | MySQL, MariaDB, Aurora MySQL, PlanetScale |
| PostgreSQL | Postgres, Supabase, Neon, Aurora Postgres, Redshift (mostly) |
| T-SQL | SQL Server, Azure SQL, Synapse |
| Oracle PL/SQL | Oracle Database, Autonomous DB |
| SQLite | SQLite, Expo, embedded apps, local dev |
If you're not sure, MySQL is a reasonable default for ANSI-compatible queries and ORM output. PostgreSQL handles RETURNING, ::cast syntax and array types that MySQL formatting would choke on.
Step 4 — Copy the Formatted Output
Click Format. The beautified query appears on the right pane with:
- Uppercase keywords (
SELECT,FROM,WHERE,JOIN) - One clause per line with consistent indentation
- Aligned
AND/ORconditions - Subqueries indented one level deeper than the outer query
- Comments preserved in place
Copy the result back to your IDE, query tool, or wherever you need it. The tool never saves or transmits the query — once you close the tab it's gone.
Example: Before and After
SELECT "user"."id","user"."email","order"."id","order"."total" FROM "user" INNER JOIN "order" ON ("order"."user_id" = "user"."id") WHERE ("user"."active" = true AND "order"."total" > 100) ORDER BY "order"."created_at" DESC LIMIT 20
SELECT
"user"."id",
"user"."email",
"order"."id",
"order"."total"
FROM "user"
INNER JOIN "order"
ON ("order"."user_id" = "user"."id")
WHERE (
"user"."active" = TRUE
AND "order"."total" > 100
)
ORDER BY "order"."created_at" DESC
LIMIT 20
The formatted version isn't magic — it's the same query. But now you can see the JOIN condition, the WHERE filters, and the ORDER BY clause at a glance instead of scrolling horizontally through a single line.
Common Gotchas When Formatting ORM SQL
%s, ?, $1, or @param placeholders. The formatter treats these as literals — they remain in the output untouched, which is exactly what you want for debugging."user"."id"). The formatter preserves quoting so you can paste straight into psql without errors.IN (1, 2, 3, ... 5000) format correctly but aren't fun to read. For these, consider rewriting with a JOIN against a temporary table rather than beautifying a 5000-element list.-- and block /* */ comments are preserved. ORMs sometimes embed the query origin as a comment — leave it in, it helps when you're tracing which bit of code generated the query.When the Formatter Can't Help
Formatting makes SQL readable, not correct. A few situations where formatting is beside the point:
- Syntax errors. The formatter accepts most malformed SQL but won't tell you what's wrong with it. Run it through your database's parser for real errors.
- Performance problems. A nicely formatted 20-table JOIN is still a 20-table JOIN. Use
EXPLAINto understand execution plans. - Dialect-specific features you selected incorrectly. Formatting Oracle SQL as MySQL will produce output but may strip or reposition Oracle-only syntax. Pick the right dialect.
For ORM-specific formatting workflows — particularly Django — see How to Format SQL from Django ORM Output.
Format SQL Without Uploading It
5 dialects. Unlimited size. Fully client-side.
Open the SQL Formatter →FAQ
How do I format SQL queries online safely? +
Use a fully client-side formatter. Most online tools upload your SQL to their server — which transmits your table names, column names and sometimes literal values. A client-side tool like ResourceCentral's SQL Formatter processes the query in your browser with zero network requests.
Which SQL dialects can be formatted? +
MySQL, PostgreSQL, T-SQL (SQL Server), Oracle PL/SQL and SQLite. Pick the dialect that matches your database so keyword casing and dialect-specific syntax format correctly.
Can I format ORM-generated SQL? +
Yes. Paste output from Django .query, SQLAlchemy echo=True, ActiveRecord, Entity Framework or any other ORM. The formatter handles quoted identifiers and parameter placeholders correctly.
Is it safe to paste production SQL into an online formatter? +
Only with a client-side formatter. See what happens when you paste SQL into an online formatter for a full breakdown of the risks with server-side tools.