SQL Minifier

Strip comments and collapse whitespace from SQL without mangling your string literals - free, no signup required.

Input SQL
Minified Output
Original: 0 B Minified: 0 B Saved: 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

When you need an SQL minifier

How to use it

  1. Paste a query or a whole script into Input SQL, click Upload File to open a .sql file, or try Load Sample.
  2. The single-line version appears on the right while you type. Click Minify to refresh it.
  3. Look at the stats line to see the size before and after.
  4. Click Copy to paste the query elsewhere, or Download to save minified.sql.
  5. 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

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.