Strip comments and collapse whitespace from SQL without mangling your string literals - free, no signup required.
Input SQL
Minified Output
Original: 0 BMinified: 0 BSaved: 0.0%
SQL Full Form
SQL stands for Structured Query Language - the standard language for relational databases (PostgreSQL, MySQL, SQLite, SQL Server, Oracle, and many more). Well-formatted SQL files are full of comments, indentation, and newlines for readability. Minifying strips those away for situations where you need a compact single-line form.
What this tool does
Strip -- line comments - Everything from -- and a space to end-of-line is removed.
Strip /* ... */ block comments - Multi-line and nested comments are removed. MySQL executable comments (/*! ... */) and optimizer hints (/*+ ... */) are kept, because they change how the query runs.
Collapse whitespace - Indentation, newlines, and repeated spaces between keywords become a single space.
Keep string literals exactly - Single- and double-quoted strings (with '' and MySQL \' escapes), backtick and bracket identifiers, PostgreSQL E'...' strings and $$ ... $$ bodies are copied byte for byte. Spaces, commas, -- and /* inside them are never touched.
Tighten punctuation - Removes spaces around ,, ;, (, and ) outside strings.
Byte savings - See original vs minified byte counts and percentage saved.
When you need an SQL minifier
Logging - When your ORM logs every query and you want a one-line, greppable form.
Embedding - When you inline SQL in code, a config file, a migration comment, or a bug report.
Pasting to chat/docs - A minified query fits on one line and doesn't suffer from formatting surprises.
Pre-build artefacts - Some build tools inline migration SQL into compiled binaries; smaller is better.
How to use it
Paste a query or a whole script into Input SQL, click Upload File to open a .sql file, or try Load Sample.
The single-line version appears on the right while you type. Click Minify to refresh it.
Look at the stats line to see the size before and after.
Click Copy to paste the query elsewhere, or Download to save minified.sql.
Beautify gives a light reformat with line breaks, useful for a first look at a query copied from a log.
A worked example
This five-line query is 106 bytes:
-- active users SELECT id, name FROM users WHERE status = 'active' /* live accounts only */ ORDER BY name;
After minifying it is 64 bytes, a saving of about 40%:
SELECT id,name FROM users WHERE status = 'active' ORDER BY name;
Both comments are gone, the line breaks are now single spaces, and the space after the comma is removed. Spaces around = are kept, because the tool only tightens commas, semicolons and brackets.
How it handles the tricky cases
Backslash escapes - MySQL lets you write a quote as \' inside a string. The minifier reads 'it\'s' as one string, so a -- comment later on the line is removed cleanly and the next line stays part of the query. If reading backslashes that way would leave a string open, but the standard reading closes it (PostgreSQL and SQL Server treat a backslash as an ordinary character, as in 'C:\'), the standard reading is used.
Spacing inside strings - text inside quotes is never changed, so 'a , b' keeps both spaces on each side of the comma.
Optimizer hints - hints written as /*+ ... */ and MySQL version comments written as /*! ... */ are kept as written.
Function bodies - PostgreSQL dollar-quoted bodies ($$ ... $$ or $tag$ ... $tag$) are kept as written, with their comments and layout.
Dialect-dependent symbols - a # starts a comment in MySQL but is an operator in PostgreSQL and part of a temporary table name in SQL Server, and --1 with no space is a comment in PostgreSQL but two minus signs in MySQL. The tool cannot know your database, so it keeps such a line as written, with its line break, which is correct in every dialect.
Client commands - the DELIMITER command of the mysql command-line client must sit on its own line, so minify the statements between those lines rather than the whole script.
The safest workflow is still to keep the formatted file as the source of truth in version control and treat the minified copy as a compact copy for logs, tickets and chat.
Privacy
Everything runs locally in your browser. Your SQL is never sent to our servers. You can minify queries that contain schema names, PII, or sensitive table structures without them leaving your machine.
Frequently Asked Questions
Will minifying change what my query does?
No. Whitespace between keywords becomes one space and comments are removed, while strings, quoted names, MySQL /*! */ code and optimizer hints such as /*+ INDEX(t idx) */ are kept exactly. A # or a -- directly followed by text means different things in different databases, so that line is kept as written with its line break.
Does it handle string escapes correctly?
Yes. Both the standard doubled quote ('') and MySQL's backslash escape (\') are understood, -- or /* inside a string is never treated as a comment, and the text inside strings is kept byte for byte.
What about dollar-quoted strings (PostgreSQL)?
Dollar-quoted strings ($$...$$ or $tag$...$tag$) used for PL/pgSQL function bodies are recognised and kept exactly as written, comments and layout included. The rest of the statement is minified around them.
How much can I realistically save?
Indented, commented SQL typically shrinks by 30-60% depending on how much documentation is inline. The primary benefit is readability in log files and chat messages, not network savings - most SQL is sent over a database connection, not a web request.
Is my SQL uploaded anywhere?
No. All minification happens in your browser. Nothing is sent to our servers, logged, or cached anywhere except the current browser tab. Paste schema-revealing queries without concern.
Can I reverse the minification?
Click Beautify for a light reformat (newlines after semicolons and around braces). For a proper SQL formatter, use a dialect-aware tool like pgFormatter, sqlformat, or your IDE's built-in formatter.
By continuing, you agree to our
Terms of Use and
Privacy Policy,
and confirm you are at least 13 years old.
You're offline
Check your connection. This page will reload on its own the moment you're back online.
Trying to reconnect...
Choose an imageUpload a new picture, or pick one you have used before.
Drag a picture hereAdd a photo from your phone
JPG, PNG, WebP or GIF. Big photos are made smaller for you. You can also paste a picture. You can crop it next.
Uploading
That did not upload.
Drop to upload
Your pictures
No picture matches that name.
Crop imageDrag to reposition · zoom to crop, or fit the whole image