How the SQL Minifier works
The minifier reads the SQL with the same tokenizer as the SQL Formatter, using the rules of the dialect you choose.
Every -- line comment and /* ... */ block comment is dropped (MySQL # comments too),
and all whitespace between tokens is removed. A single space is put back only where two tokens would otherwise run
together, such as two words (FROM customers), or two operators that would change meaning or start a comment
(- -1).
String literals, dollar-quoted strings and quoted identifiers are copied exactly, including any spaces or line breaks
inside them. GO batch separators (SQL Server) and DELIMITER commands (MySQL) keep their own lines
because client tools only recognise them there. The status message compares the UTF-8 size before and after. The SQL
is not run or validated.
How to use the SQL Minifier
- Paste your SQL into the input box, open a .sql file, or select Load example.
- Choose the dialect so its strings, quoted names and comments are recognised. Tick Keep hint comments if your SQL relies on MySQL /*! ... */ or /*+ ... */ optimizer hints.
- Select Minify SQL, or press Ctrl + Enter (Cmd + Enter on a Mac).
- Check the size saved in the status message, then copy the result or download it as a .sql file.
Example
This query (138 bytes):
-- Active German customers
SELECT
id,
name /* display name */
FROM customers
WHERE country = 'DE'
AND note <> 'VIP customer';
is minified to 75 bytes, saving 63 bytes (45.7%) and removing 2 comments. The two spaces inside the string are kept:
SELECT id,name FROM customers WHERE country='DE' AND note<>'VIP customer';
Common use cases
- Embedding a query in application code, a JSON configuration file or an environment variable where line breaks are awkward.
- Removing developer comments from SQL before it is shared or shipped in a script.
- Reducing the size of large generated SQL scripts before storing or sending them.
- Putting a query on a single line for a command-line tool or a log search.
Common errors and how to fix them
- Comments disappeared from the query
- Removing comments is part of minifying, and the result reports how many were removed. If a comment carries an optimiser hint that your database actually reads, keep the formatted version instead.
- Spaces inside a string literal were not removed
- String literals, dollar-quoted strings and quoted identifiers are copied exactly, including spaces and line breaks. Collapsing them would change the data the query writes or matches.
- The one-line query breaks when pasted into code
- Minifying does not escape the result for a host language. A query containing single quotes still needs escaping for your C#, Python or JavaScript string literal.
Frequently asked questions
Is minified SQL still valid?
Yes, as long as the original was. The minifier removes comments and replaces whitespace with nothing where tokens cannot merge, and with a single space where they could, for example between two words, or between two operators that would otherwise form a comment such as - -1.
Are strings and quoted identifiers kept exactly?
Yes. Anything inside 'string literals', N'' strings, PostgreSQL $$ dollar-quoted strings, [brackets], "double quotes" or `backticks` is copied unchanged, including spaces, line breaks and characters that look like comments.
What happens to GO and DELIMITER lines?
They are client commands that only work on their own line. In SQL Server mode a GO line stays on its own line, and in MySQL mode each DELIMITER command keeps its own line, so the minified script still runs in tools such as SSMS, sqlcmd and the mysql client.
Does the minifier run or validate the SQL?
No. It never executes the SQL or connects to a database. It only reports problems that stop it from reading the text, such as a string or block comment that is not closed.
Is my SQL uploaded to your server?
No. Minifying happens in your browser, and your SQL is not sent to our server.