SQL Minifier
This SQL minifier collapses a formatted query down to a single line: comments are removed, every run of whitespace becomes one space, and the result is ready to paste into a config file, an environment variable, a JSON field or a log search box where line breaks are awkward. String literals and quoted identifiers are recognised properly rather than pattern-matched, so a double dash inside a string is never mistaken for the start of a comment and a semicolon inside a value never splits a statement. You can keep comments if you need them, and keep one statement per line when minifying a whole script.
How it works
Strips comments and collapses every run of whitespace to a single space, giving you a one-line query to paste into a config file, an environment variable, a JSON field or a log search.
String literals, quoted identifiers and the contents of block comments you choose to keep are left exactly as they are, so a semicolon or a double dash inside a string is never mistaken for structure.
Everything runs in your browser — nothing you paste is sent to a server.
How to minify SQL
- Paste your query or script into the input on the left.
- Decide whether to keep comments and whether each statement gets its own line.
- Copy the compacted result, or download it as a
.sqlfile.
Why a one-line query is useful
Configuration files, environment variables, JSON fields, CI pipeline definitions and log search boxes all deal badly with line breaks. Embedding a multi-line query in any of them means escaping every newline, and the result is harder to read than the compacted version would have been. Minifying sidesteps the problem entirely.
Why tokenising matters here
A naive minifier that strips everything after -- will corrupt this query:
SELECT * FROM notes WHERE body = 'see -- for details'; The double dash is inside a string literal, so it is part of the value, not the start of a comment. The same applies to semicolons inside strings, which a naive statement splitter would treat as a boundary. This tool tokenises the input first, so literals, quoted identifiers and comments are each recognised for what they are.
Minifying does not make queries faster
Database engines parse SQL before executing it, and whitespace is discarded at that stage. A minified query plans and runs exactly like the formatted one. This is about fitting a query somewhere awkward, not about performance.
Common use cases
- Putting a query into an environment variable or a JSON config field.
- Pasting a query into a log search or an issue tracker without it wrapping.
- Shrinking a long script before embedding it in a deployment definition.
Frequently asked questions
How do I minify SQL?
Paste your query or script into the left panel. The compacted version appears on the right, ready to copy or download.
Why would I want a one-line query?
Configuration files, environment variables, JSON fields, CI definitions and log search boxes all handle a single line far better than a multi-line block. Minifying avoids the escaping gymnastics that line breaks otherwise require.
Are comments inside strings safe?
Yes. The input is tokenised first, so a double dash or a slash-star sequence inside a string literal is treated as part of the value, not as the start of a comment.
Can I keep the comments?
Yes. Tick keep comments and they are preserved — line comments keep their trailing newline, since they would otherwise swallow the rest of the query.
What about a script with many statements?
Leave one statement per line ticked and each statement ending in a semicolon starts a new line, which keeps a long script readable while still removing all the wasted whitespace inside each statement.
Does minifying make my query faster?
No. Database engines parse SQL before executing it, so whitespace has no effect on performance. This is about fitting the query somewhere, not speeding it up.
Related tools
SQL Formatter & Beautifier
This SQL formatter breaks a one-line query into readable clauses, across a dozen dialects.
SQL to JSON Converter
This SQL to JSON converter reads INSERT statements and gives you an array of typed records.
SQL Escape / Unescape
This SQL escaper doubles single quotes, with an option for MySQL backslash escapes.