ZumaTools

SQL Formatter

Paste any SQL query to get a cleanly indented, uppercase-keyword version instantly — or minify it to a single line.

Formatted SQL
 
Options

Formatting uses a heuristic, not a full SQL parser — always review the output. Everything runs on your device; nothing is sent anywhere.

How it works

  1. Paste or type your SQL query into the input box on the left.
  2. The formatted version appears live on the right, with uppercase keywords, one clause per line, and indented subqueries.
  3. Switch to Minify to collapse the query to one line, then press Copy to grab the result.

Frequently asked questions

How does this SQL formatter decide where to break lines?
It tokenizes your query and starts a new line before major clauses such as SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, and LIMIT. Subqueries wrapped in parentheses are placed on their own indented block, so nesting depth stays visible at a glance.
Will it change my string literals or identifiers?
No. Text inside single quotes, double quotes, and backticks is passed through untouched, including embedded spaces and escaped quotes. Only bare keywords are uppercased, so column names, table names, and data values keep their exact original casing.
Is my SQL sent to a server?
No. Formatting and minifying run entirely in your browser with plain JavaScript, and the page makes no network requests with your input. That makes it safe to paste queries containing production table names or sensitive WHERE-clause values.
Which SQL dialects does it support?
The formatter is dialect-agnostic and works with ANSI SQL plus common PostgreSQL, MySQL, SQLite, and SQL Server syntax. Because it is a heuristic layout tool rather than a full parser, it never validates your query — it simply tidies whatever you give it, so vendor-specific extensions pass through cleanly.
What is SQL minification useful for?
Minify collapses a query to a single line with normalized spacing and comments removed. That is handy for embedding SQL in code as a one-line string, pasting into log searches or curl commands, and comparing two queries after normalizing their whitespace.

About this tool

This SQL formatter turns dense, single-line queries into readable, consistently indented SQL. Paste a query and the formatted result appears immediately: keywords are uppercased from an embedded keyword list, each major clause — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, LIMIT — starts on its own line, and subqueries are indented by parenthesis depth so nested logic reads like an outline. A one-click Minify mode does the reverse, collapsing everything onto one line with comments stripped, which is ideal for embedding queries in application code or pasting them into log tooling.

Under the hood the tool tokenizes your input rather than running naive find-and-replace. String literals in single quotes, quoted identifiers, backticked names, numbers, comments, and operators are each recognized as distinct tokens, which is why a WHERE clause like name = ’O’’Brien’ or a column called order_select survives formatting intact. Everything happens client-side in your browser: no upload, no server round-trip, no logging. You can safely format queries that reference internal schemas or contain real customer values.

Typical uses include cleaning up queries copied from ORM debug output or slow-query logs, normalizing SQL before a code review so diffs show logic changes instead of whitespace noise, and reformatting long analytics queries with several levels of nested SELECTs before editing them. The live output means you can also type SQL directly and watch the structure emerge as you go.

One honest caveat: this is a formatting heuristic, not a full SQL parser. It does not build a syntax tree, so unusual constructs — deeply nested CASE expressions, vendor-specific procedural blocks, or unbalanced parentheses — may not break exactly where a dialect-aware pretty-printer would. For everyday SELECT, INSERT, UPDATE, and DELETE statements it produces clean, predictable output, and it will never alter the meaning of your query, only its whitespace and keyword casing.

Related tools