Use the free SQL Minifier below: your data never leaves your browser — all work happens on your device, and nothing is uploaded to any server.
Why Minify SQL?
SQL queries travel in many places where size matters: inside application code, in URLs for reporting tools, in logs, in migration files, and in messages between services. A query written for humans, with comments, generous line breaks, and careful indentation, is easy to read but wasteful in those channels. Minifying compacts it to a single line with single spaces, comments removed, so it takes less room and is easier to embed, while doing exactly the same work in the database.
The tool above minifies entirely in your browser. It removes line comments and block comments, collapses runs of whitespace to single spaces, and tidies spaces around commas and semicolons. Crucially, it leaves string literals exactly as they are, so a quoted value containing spaces or comment-like text is never damaged. An optional switch uppercases keywords, which some teams prefer for the compact form.
How to Use the Tool
Paste a query into the input box and press Minify. The compact query appears below, with the sizes before and after and the percentage saved. Keep “Remove comments” ticked unless your comments carry meaning for the receiver, and tick “UPPERCASE keywords” if your house style writes keywords in capitals. Copy the result or download it as a SQL file.
Try the Load example button to see a typical transformation: a commented, multi-line report query becomes one clean line, with the quoted date and the quoted status value untouched. That string safety is the feature that separates a real minifier from a naive find-and-replace, which would happily delete the inside of a quoted value that happened to contain “–“.
How It Keeps Strings Safe
The minifier walks the query character by character, tracking whether it is inside a single-quoted, double-quoted, or backtick-quoted string. Outside strings, “–” starts a line comment and “/*” starts a block comment, and both are removed when the option is on. Inside strings, those same characters are ordinary text and are copied through untouched. Doubled quotes inside strings, the SQL way to include a quote, are handled as well, so a value like “it”s” survives intact.
Whitespace handling follows the same rule. Outside strings, any run of spaces, tabs, and new lines becomes one space, and spaces before commas and semicolons are dropped. Inside strings, every space stays exactly where it was, because a value with two spaces is a different value from one with one space, and a minifier must never change data.
When Minifying Helps
Minifying helps most when queries are embedded somewhere with size or line limits, when they are logged and log volume costs money, or when they are compared as strings and formatting noise creates false differences. It also helps when pasting a query into a chat message, a ticket, or a single-line field that would otherwise mangle line breaks.
It does not make a query faster. The database parses the compact form in the same way, and execution time depends on indexes, data, and the query plan, not on whitespace. If a query is slow, minifying it will not help; examining its execution plan and its indexes will. Do not confuse a smaller query with a better query.
What Minifying Does Not Do
The tool does not rewrite the query, optimise it, or change its meaning. It does not reorder conditions, remove supposedly redundant parts, or rename tables. Those transformations can change results in subtle ways, and they belong to a query optimiser or a careful human, not to a formatter. The output is guaranteed to be the same query with less air in it, nothing more.
It also does not validate the query. A minified invalid query is still invalid, just shorter. If the output fails in your database, check the original first: a missing comma or an unbalanced parenthesis in the input will survive minification unchanged, because the tool preserves everything except whitespace and comments.
Keeping the Readable Original
Always keep the formatted query as your source. Store it in version control, review it there, and generate the minified form when you need it. If you only keep the minified form, the next person to change the query must first expand it by hand, which wastes time and invites errors, and the comments that explained why the query is written that way are gone for good.
A good habit is to keep both side by side during development: the readable query in your code with a comment explaining its purpose, and the minified form only where the channel demands it. That way readability serves the humans and compactness serves the machines, and neither has to compromise for the other.
