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

Love the tools? Lose the ads.

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