Skip to main content
SQL Guide

How to Format
SQL Queries

Turn a wall of minified SQL into something readable — in your browser, across 5 dialects, without uploading it anywhere.

5 min read·Updated Apr 2026

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:

Raw SQL
Hand-written queries from your IDE, SQL client, or .sql migration files.
ORM-generated SQL
Output from Django .query, SQLAlchemy echo=True, ActiveRecord to_sql, EF Core logs.
Minified / single-line SQL
The kind of query that scrolls off the right of your terminal. Paste as-is, let the formatter handle it.
Multi-statement scripts
Whole .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
MySQLMySQL, MariaDB, Aurora MySQL, PlanetScale
PostgreSQLPostgres, Supabase, Neon, Aurora Postgres, Redshift (mostly)
T-SQLSQL Server, Azure SQL, Synapse
Oracle PL/SQLOracle Database, Autonomous DB
SQLiteSQLite, 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:

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

❌ Before (ORM output)
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
✅ After (formatted)
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

Parameter placeholders
ORM output often contains %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.
Quoted identifiers
Django and SQLAlchemy wrap everything in double quotes ("user"."id"). The formatter preserves quoting so you can paste straight into psql without errors.
Massive IN clauses
Queries with 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.
Comments in the input
Single-line -- 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:

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.

Related