Home/Developer Tools/SQL Formatter & Minifier
🗃

SQL Formatter & Minifier

FREE

Lay out SQL clause by clause, or collapse it to one line

Free · No sign-up required
Loading...

What the SQL formatter does

The formatter takes a SQL statement — hand-written, copied from a log, or generated by an ORM as one enormous line — and lays it out with each clause on its own line and consistent indentation, so the structure is visible at a glance. The minify mode does the reverse, collapsing whitespace into a single line for embedding in code or pasting into a tool with a small input box. Formatting is purely textual and does not change what the query does. It runs in your browser, so queries containing table names or literal values are never sent anywhere.

Before and after

Before: select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.created_at > '2026-01-01' and u.status = 'active' group by u.id, u.email having count(o.id) > 3 order by orders desc limit 50; After: SELECT u.id, u.email, COUNT(o.id) AS orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.created_at > '2026-01-01' AND u.status = 'active' GROUP BY u.id, u.email HAVING COUNT(o.id) > 3 ORDER BY orders DESC LIMIT 50;

Conventions the formatter applies

  • Keywords uppercased — SELECT, FROM, WHERE, JOIN and friends, so they stand out from identifiers.
  • One clause per line — each major clause starts a new line at the left margin.
  • Conditions indented — AND / OR terms are indented under WHERE and HAVING.
  • Selected columns on separate lines when there are several.
  • Subqueries indented a level deeper than the clause containing them.

Identifiers, string literals and comments are left exactly as written — the formatter does not know your schema and does not try to guess.

Why format SQL at all

  • Debugging — a 40-clause query on one line hides a missing JOIN condition; formatted, the mistake is obvious.
  • Code review — reviewers can follow the logic and diffs show which clause changed.
  • Reading ORM output — SQL logged by Django, Rails, Prisma or Hibernate is generated for the database, not for humans.
  • Documentation — queries in runbooks and wikis should be readable years later.
  • Consistency — a team that formats the same way spends less time arguing about style.

When to minify

Minified SQL is for machines: a query string constant in application code, a URL parameter to a reporting API, or a field in a YAML config. Databases do not care about whitespace, so minifying has no performance effect on execution — the only saving is a few bytes over the wire. Always keep the formatted version in source control and generate the minified one.

Dialect notes

DialectFormats correctly?Watch for
PostgreSQLYes$$-quoted function bodies are treated as text
MySQL / MariaDBYesBacktick identifiers preserved
SQLiteYes
SQL Server (T-SQL)MostlySquare-bracket identifiers preserved; procedural blocks (BEGIN…END) are laid out simply
Oracle PL/SQLPartiallyPackage bodies and anonymous blocks are formatted as plain statements
BigQuery / SnowflakeYesStandard clauses; dialect-specific functions pass through

Frequently asked questions

Does formatting change the query's result?

No. Only whitespace and keyword case change. String literals, identifiers and comments are untouched, so the query executes identically.

Can it format multiple statements at once?

Yes. Statements separated by semicolons are each formatted and kept in order.

Why did my comment move?

Comments are kept but attached to the nearest token; a trailing comment may end up on the following line. Block comments (/* */) are preserved in place.

Does it validate the SQL?

No. It formats what it can parse and leaves the rest alone; a syntax error will still be a syntax error. Run the query against your database for validation.

Can I choose lowercase keywords or a different indent?

Not in this tool; it applies one consistent style. Editors such as VS Code with a SQL extension, or DataGrip, offer configurable styles.

Is my query sent to a server?

No. Formatting runs in your browser, so table names and literal values in the query stay on your device.

More tools in this category

📋
JSON Tools
View tree, format, validate and minify JSON
📄
YAML Beautifier & Validator
Format YAML and find the line that breaks it
📋
XML Tools
Beautify, validate and convert XML to JSON
📝
Markdown Tools
Preview Markdown, convert to HTML and generate tables
🔑
JWT Encoder & Decoder
Decode a JWT's header and payload, or sign one with HS256
🔐
URL & Base64 Encoder / Decoder
Percent-encode for URLs or convert to and from Base64