What This Tool Does (And Why It's String-Literal Safe)
This sql minifier online strips -- line comments and /* */ block comments and collapses whitespace, but the key detail is how it strips comments: it scans character by character and tracks whether it is currently inside a single-quoted or double-quoted string, so a value like 'foo--bar' or a string containing /* is never mistaken for a real comment. Many cheaper regex-based sql minifiers get this wrong and will silently corrupt a query the moment a string literal happens to contain a comment-like sequence. This one won't, since comment detection only fires outside of string boundaries.
How to Minify SQL With This Tool
Paste your SQL into the input field, toggle "Strip comments" if you want to remove comments from sql, and the minified output appears immediately with the character counts and percentage saved. There is nothing to install and no build step to configure, so you can minify sql online, or minify sql query online for a longer script, in the time it takes to paste and copy. Copy the result directly, it is valid SQL, just smaller.
What Gets Removed vs. What Gets Preserved
Line comments starting with -- and block comments wrapped in /* */ are removed entirely when that option is on, but only outside of string literals, comment-like text inside a quoted value is always preserved exactly. Whitespace is then collapsed everywhere, all runs of spaces, tabs, and newlines become a single space, making this a genuine sql whitespace remover, and extra spacing around parentheses, commas, and semicolons is removed so the query reads as one compact line.
A Known Limitation: Whitespace Inside String Literals
While comment stripping is fully string-literal-aware, the whitespace-collapsing step is not: it runs across the entire query, including inside quoted string values. In practice this means a string literal with deliberate internal spacing, like 'a b' with multiple spaces, will have that spacing collapsed to a single space along with everything else. For typical SQL, table names, column names, WHERE clause values, this rarely matters, but it's worth knowing if your query stores meaningfully whitespace-sensitive string data.
Common Uses for a SQL Minifier
Embedding a query as a single-line string constant in application code, needing to compress sql query text before logging or storing it, trimming a query before pasting it into a support ticket or forum post, and comparing before-and-after character count are all common reasons to reduce sql query size with a sql compressor online like this one.