Skip to content

SQL Minifier

Minified SQL —
Original characters
—
Minified characters
—
Size reduction
—
Comments removed
—
String literals kept
—

Paste a query and the minifier removes line and block comments, collapses every run of spaces, tabs and newlines, and drops spaces around commas, brackets and operators. Text inside quotes is never changed. A 50-character SELECT with a trailing — comment shrinks to 33 characters, a 34% reduction.

About this tool

Long SQL lives happily in a .sql file, but it is awkward to embed in a config value, a log line, a JSON string or a one-line shell command. This minifier rewrites a query onto a single line without changing what the database will run. It reads the text the way a SQL lexer does: single-quoted strings, double-quoted, backtick and bracketed identifiers pass through byte for byte, comments are removed, and spaces are kept only where two words or two operators would otherwise fuse. Optimizer hints written as /+ … / and MySQL /! … / blocks are kept, because some engines act on them. The output is not a validator, though: a query with a syntax error comes out minified and still broken.

How to use it

  1. Add the query

    Paste one or more statements into the box, or open a .sql or .txt file from your device.

  2. Read the one-line result

    The minified SQL appears as you type, together with the before and after character counts.

  3. Check the counts

    Comments removed and string literals kept help confirm that nothing inside quotes was touched.

  4. Copy it out

    Use Copy result to paste the compact query into code, a config file or a terminal.

Examples

A short SELECT with a line comment

SQL query
SELECT a , b FROM t — list WHERE x = 'a b' ;

Result Minified SQL: SELECT a,b FROM t WHERE x='a b';
Original characters: 50
Minified characters: 33
Size reduction: 34%
Comments removed: 1
String literals kept: 1

  1. Removed 1 comment.
  2. Collapsed whitespace between 11 tokens; a single space stays only between two words or two operators.
  3. Size: 50 → 33 characters, 34% smaller.

The — comment and the padding disappear, but the two spaces inside the quoted value 'a b' stay, because they are part of the data.

Subtracting a negative number

SQL query
SELECT a – -1 /* note */ FROM t

Result Minified SQL: SELECT a- -1 FROM t
Original characters: 31
Minified characters: 19
Size reduction: 38.7%
Comments removed: 1
String literals kept: 0

  1. Removed 1 comment.
  2. Collapsed whitespace between 7 tokens; a single space stays only between two words or two operators.
  3. Size: 31 → 19 characters, 38.7% smaller.

The space between the two minus signs is kept, since joining them would turn the rest of the line into a — comment.

How it is calculated

output = tokens joined with no separator, except one space between two word tokens or two operator tokens

word token
a keyword, identifier, number, quoted string or quoted identifier
operator token
a run of symbols such as =, <>, ||, + or –
punctuation
parentheses, commas and semicolons, which never need a space beside them

The text is split into tokens following SQL lexical rules. Anything inside single quotes, double quotes, backticks or square brackets is one token and is copied exactly, including doubled quotes used as escapes. A — comment ends at the line break and a /* / comment at its closing mark; both are dropped unless the block starts with /+ or /*!. Two operators stay apart so that a – -1 never becomes the comment marker –.

When not to use it

  • Stored procedures that rely on DELIMITER changes in a MySQL client script may break when put on one line.
  • Queries kept in version control are easier to review and diff in their formatted form.
  • PostgreSQL dollar-quoted bodies such as $$ … $$ are not treated as strings, so check them by hand.

Common mistakes

  • Minifying a script that uses # as a MySQL comment marker, which this tool reads as part of a name.
  • Expecting the output to run faster; databases parse whitespace in microseconds, so the gain is size, not speed.
  • Forgetting that a — comment with no line break after it swallows the rest of a one-line query if added back later.

Frequently asked questions

Will minifying change what my query returns?

No. Only comments and whitespace between tokens are removed, and SQL treats any amount of whitespace between tokens the same. Text inside quotes, including spaces and line breaks within a string literal, is copied exactly.

Why is there still a space between some symbols?

Two operators written side by side can fuse into a different one. The clearest case is a – -1: without the space it becomes a–1, and everything after — would turn into a comment. The tool keeps one space between any two operator tokens to avoid this.

Are optimizer hints removed?

Block comments that start with /+ (Oracle and MySQL hints) or /! (MySQL version-conditional code) are kept as written, because the database reads them. All other — and /* */ comments are removed.

Does it work for several statements at once?

Yes. Each statement keeps its semicolon and they are joined on one line, so a migration file with several CREATE and INSERT statements becomes a single line that most clients still execute in order.

Which SQL dialects does it understand?

The tokenising rules cover standard SQL plus the quoting styles of MySQL (backticks), SQL Server (square brackets) and PostgreSQL or Oracle (double quotes). Dialect features such as dollar quoting or # comments are not recognised.

Is my SQL sent to a server?

No. The minifying runs in your browser, so table names, credentials in connection strings or customer data inside literals never leave your device.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, October 23). SQL Minifier. Tools Directory. Retrieved October 26, 2026, from https://tools.milunir.com/developer-tools/developer-reference/sql-minifier/

MLA

Tools Directory Editorial Team. “SQL Minifier.” Tools Directory, 23 Oct. 2026, https://tools.milunir.com/developer-tools/developer-reference/sql-minifier/. Accessed 26 Oct. 2026.

Chicago

Tools Directory Editorial Team. “SQL Minifier.” Tools Directory. Last modified October 23, 2026. Accessed October 26, 2026. https://tools.milunir.com/developer-tools/developer-reference/sql-minifier/.

Link<a href="https://tools.milunir.com/developer-tools/developer-reference/sql-minifier/">SQL Minifier – Tools Directory</a>