SQL Minifier
FV-12Paste SQL to remove comments and collapse whitespace. Strings, quoted names and dollar-quoted bodies are copied exactly, so the statements mean the same thing.
Runs in your browser. Nothing is uploaded.
SQL
Minified SQL
How to use it
- Paste your SQL into the input box, or open a .sql file (up to 5 MB).
- For MySQL scripts, tick the MySQL option so # comments are handled. Tick the backslash option if your strings use backslash escapes.
- Choose Minify and copy or download the result.
- Choose Size saved to see the byte count before and after.
What is protected
Text inside single-quoted strings, double-quoted names, [bracketed] names, backtick names and $$ or $tag$ dollar-quoted bodies is copied exactly. A -- or /* inside a string is therefore not treated as a comment, and extra spaces inside a string stay. Doubled quotes such as 'it''s' are understood. Block comments are treated as nested, as in SQL Server and PostgreSQL, unless the MySQL option is ticked; Oracle and SQLite do not nest them. And /*! and /*+ comments are kept by default, since MySQL and Oracle read them as instructions.
Where spaces are removed
Spaces are removed only around commas and semicolons and just inside parentheses. Operators keep their spaces, so a - -b never turns into a -- comment. Everything else collapses to a single space. A line that contains only GO, a DELIMITER line from the MySQL client or a lone / from SQL*Plus stays on its own line, because those tools read it line by line. The result is a one-line script apart from those GO lines.
Dialect differences to know
MySQL treats -- as a comment only before a space, and # as a comment to the end of the line; the MySQL option follows those rules. Without it, a # followed by a space is refused rather than guessed at. Strings that use backslash escapes, as MySQL does, need the backslash option. PostgreSQL E'...' strings are recognized without it. Backslash commands from psql are refused.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
String starting at line 3 is never closed (missing '). | A single-quoted string has no closing quote. | Add the quote. In MySQL, tick the backslash option if the string uses \' escapes. |
Comment starting at line 6 is never closed (missing */). | A /* comment has no matching */. | Add the closing */. |
Line 4: # followed by a space starts a comment in MySQL only. Tick the MySQL option so the comment is removed, or delete it. | A hash comment was found while the MySQL option is off. | Tick the MySQL option, or remove the comment. |
Questions people ask
How do I remove comments from SQL?
Paste the script, choose Minify, and both -- line comments and /* */ block comments are removed, along with extra whitespace. Anything inside quotes is left alone.
Will minifying change what my query does?
It should not. Comments and spacing do not affect execution, and strings and quoted names are copied exactly. Hint comments such as /*+ ... */ are kept by default because they can. Review scripts that rely on line-based tools such as GO.
Why is my MySQL script refused?
A # followed by a space starts a comment in MySQL but is an operator or error elsewhere. Without the MySQL option the tool stops and asks, instead of guessing. Tick MySQL comments to remove them.
Does it work for stored procedures?
Yes for the text. Dollar-quoted bodies and strings are copied exactly. Keep in mind that a body in a language where whitespace matters, such as a PL/Python function, is left untouched on purpose, which is why dollar-quoted text is copied.
What does GO do in the output?
GO is a batch separator for SSMS and sqlcmd, not SQL itself. A line holding only GO, optionally with a count, stays on its own line so the batches still split in the same places.
Can it format SQL instead?
This page only shrinks it and does not change keywords or names. To lay out a query with indentation and line breaks, use the SQL Formatter on this site.
About this tool
Removes -- and /* */ comments and collapses whitespace outside strings. Text inside '...', "...", [...], `...` and $$...$$ (or $tag$...$tag$) is copied exactly, and comments inside those are kept as text. Spaces are removed only around commas, semicolons and just inside parentheses; operators keep their spaces so that a - -b can never become a comment. A line that holds only GO, a DELIMITER line or a lone / stays on its own line, as SSMS, the MySQL client and SQL*Plus need. Block comments nest, as in SQL Server and PostgreSQL, unless the MySQL option is ticked; Oracle and SQLite do not nest them, so check a script that has /* inside a comment. /*! and /*+ comments are kept by default because MySQL and Oracle read them as instructions. In MySQL, -- starts a comment only before a space and # starts one too; tick the MySQL option for that. It does not check SQL syntax, and psql backslash commands are refused because they end at a line break.