Skip to main content

SQL Minifier

Minify a SQL query by stripping -- / # / block comments and collapsing whitespace to single spaces, while leaving string literals and quoted identifiers byte-for-byte untouched — even ones containing '' escaped quotes or comment-like -- and /* */ sequences.

Input

Output

Minified SQL
Size Stats
PropertyValue
No data yet
Was this helpful?

Guides

Shrink a SQL query down to the smallest form that still runs exactly the same. The SQL Minifier strips -- and # line comments plus /* */ block comments, and collapses every run of indentation, line breaks and extra spaces into a single space — without ever touching the text inside a string literal or a quoted identifier.

How to use it

  1. Paste a SQL query into the input box.
  2. The minified query appears instantly in the output panel, along with a size comparison (original bytes, minified bytes, and the percentage saved).
  3. Copy the result, or download it as minified.sql.

Minifying is deterministic, so there's nothing to configure — paste and go.

Will it corrupt a query that has -- or /* */ inside a string?

No — the part a naive minifier gets wrong. A regex stripper that blindly deletes --... or /* ... */ anywhere it finds them will mangle a query containing a value like 'my--value' or 'a /* not a comment */ b', because it can't tell a real comment from a comment-shaped substring inside quotes. This tool uses a character-by-character scanner that tracks whether it's currently inside a single-quoted string, a double-quoted string/identifier, or a MySQL backtick-quoted identifier. Comments are recognized only outside all three — everything inside a quoted region, including a literal -- or /* */, passes through byte-for-byte.

What about escaped quotes, like it''s?

Handled correctly. Doubling the quote character — '' in a single-quoted string, "" in a double-quoted one, or `` in a backtick identifier — is the standard escape for "a literal quote here," not the end of the string. The scanner recognizes the doubled pair and keeps reading, so 'it''s a --test-- value' stays one unbroken literal instead of being split apart or having its embedded -- mistaken for a comment.

Does it rewrite spacing around operators like =, , or -?

Whitespace outside quotes always collapses to a single space, but the tool deliberately doesn't squeeze spaces flush against punctuation the way some minifiers do. Tightening a - -1 down to a--1, for example, would accidentally manufacture a brand-new -- comment that silently swallows the rest of the query — a worse bug than the whitespace it was trying to save. A few extra bytes buy that guarantee.

Is my SQL sent to a server?

No. Minification runs entirely in your browser (or via the API, in memory) — the query text is never logged or stored.

When is this useful?

  • Shrinking a query embedded in application code, a migration file, or a config value.
  • Producing a compact one-liner for logs or a support ticket without losing the query's meaning.
  • Cleaning up a query that was copy-pasted with inconsistent indentation before checking it into version control.

Does it reformat or validate my SQL?

No — it only removes comments and collapses whitespace; it doesn't parse the grammar, reindent it, or catch syntax errors. For readable, indented SQL, use the SQL Formatter instead.

sqlminifiercompressdatabasedeveloper

More ways to use this tool

REST API

curl -X POST https://api.iotools.cloud/v1/tool/sql-minifier \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sqlInput": "SELECT\n  u.id,\n  u.name -- the display name\nFROM…"
  }'

Swap in your own key from your account. The tool's fields are the body — no wrapper.

Ask an AI agent

Use the IOTools `sql-minifier` tool (SQL Minifier) on this input:

YOUR_INPUT_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Embed widget

<iframe
  src="https://iotools.cloud/embed/sql-minifier/"
  width="100%" height="520" frameborder="0" scrolling="no" loading="lazy"
  title="SQL Minifier — iotools.cloud"
  sandbox="allow-scripts allow-forms allow-same-origin allow-downloads allow-popups allow-popups-to-escape-sandbox"
  allow="clipboard-write"
  style="width:100%;border:1px solid #e5e7eb;border-radius:12px;overflow:hidden"></iframe>
<script src="https://iotools.cloud/embed.js" async></script>

Drop this into your own page — free, no key required, just a link back.

Cost per callFrom 5 credits

Also available with

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.