Back to Tools

SQL Minifier

Compress SQL queries by removing whitespace and comments for optimal performance

MINIFY PRO
Source Query
Compressed Output

                    

Squash a query into one compact line

Sometimes SQL has to travel in a cramped space: a single-line config value, a command-line argument, a log message, an environment variable or a string literal in source code. The SQL Minifier removes comments and turns all runs of whitespace, including line breaks, into single spaces so a multi-line query becomes one compact line.

How to minify

  1. Paste your statement into the Source Query area, or press Sample to load a commented example. Clear empties the field.
  2. Click Minify SQL Query.
  3. Look at the Compressed Output. Three badges above it report the Original length, the Minified length and the percentage Saved.
  4. Press Copy to take the result.

What is removed

  • Block comments written between slash-star and star-slash markers.
  • Line comments that start with two hyphens, through to the end of the line.
  • Extra spaces, tabs and newlines, which become a single space.
  • Leading and trailing spaces around the whole statement.

Good moments to use it

Embedding a query in a JSON or YAML file where line breaks are awkward. Pasting a statement into a shell command without escaping newlines. Reducing noise in a log line when you record the SQL your service ran. Stripping developer notes from a query before you share it with a client. Checking how much of a query's length was whitespace and commentary.

Caveats before you paste it into production

The minifier uses plain pattern matching rather than a full SQL parser, which leads to a few edge cases. A double hyphen inside a string literal, such as a value like 'a -- b', will be treated as the start of a comment and the rest of that line removed. Runs of spaces inside quoted strings are also collapsed to one, which could alter a literal that depended on its spacing. Special comments that carry meaning, such as MySQL version hints or Oracle optimizer hints written in comment form, are removed along with ordinary ones. Spaces around commas and operators are kept, so the result is compact rather than as short as possible. Always compare the minified statement with the original against a test database. Minifying does not speed up execution, since databases ignore whitespace. Everything happens in your browser.


Related Tools

Related Tools


Frequently Asked Questions

Does minified SQL run faster?
No. The database parses whitespace and comments away before executing, so performance is the same. Minifying only makes the text shorter and easier to fit on one line, for example in a config value or a log.
Are comments removed?
Yes. Both block comments and comments starting with two hyphens are deleted. That includes hint-style comments such as optimizer hints, so if a hint matters to your query, add it back after minifying or skip this tool.
Can minifying break a query?
It can in edge cases. A double hyphen inside a quoted string is read as a comment, and repeated spaces inside a string are squeezed to one. Check the output on a test database whenever string literals contain such patterns.
What do the Original, Minified and Saved numbers mean?
Original and Minified are character counts before and after processing. Saved is the percentage reduction in length. A heavily indented, commented query will show a larger saving than one that was already compact.
Can I reverse the process?
Comments are gone for good, but you can restore the layout by pasting the minified text into a SQL formatter or beautifier. That re-indents the clauses, though it cannot bring back deleted comments.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.