SQL Minifier
Remove line comments, block comments and surplus whitespace from SQL so it fits on one compact line. A purpose-built tokeniser keeps string literals, quoted identifiers and dollar-quoted blocks exactly as written, so text such as '--' or '/*' inside a string is never mistaken for a comment.
Minify Your SQL
This tool only tokenises text. It never connects to a database and never runs your SQL.
Size comparison
Minified SQL
How to Use the SQL Minifier
- Paste your SQL into the box.
- Pick the dialect that matches your database so strings, comments and identifiers are recognised correctly.
- Decide whether to keep optimizer hints (/*+ ... */) and MySQL conditional comments (/*! ... */); both can change how a query runs.
- Press Minify, then copy the result or download minified.sql.
About This Tool
Developers embedding queries in code or config files, people pasting SQL into tools with length limits, and anyone cleaning commented scripts before sharing them.
Input: SQL text ยท Output: Compact SQL.
Features and Limitations
Features
- Understands single, double and back-quoted text, [bracketed] identifiers, E'' strings and $tag$ dollar quotes.
- Optional nested block comments for PostgreSQL and q'[ ]' quoting for Oracle.
- Keeps optimizer hints and MySQL version comments by default.
- Reports unterminated strings or comments with line and column.
- Shows bytes saved.
Limitations
-
T-SQL
GObatch separators and MySQLDELIMITERcommands are client commands that need their own line; the minifier does not special-case them. - It does not parse SQL, so it cannot tell you whether the query is valid.
-
In MySQL mode a
--is a comment only when followed by whitespace, as in MySQL itself; in other modes it is always a comment. - Whitespace inside strings, identifiers and dollar-quoted blocks is intentionally left unchanged.
- Results are computed in your browser; nothing you enter is sent to a server.
Example
SELECT * FROM t WHERE note = 'a -- b'; -- trailing
becomes SELECT * FROM t WHERE note='a -- b';. The
-- inside the quotes survives; the trailing comment
is removed.
Frequently Asked Questions
How are comments inside strings handled?
They are left alone. The tokeniser reads a quoted string
as one unit, so '-- not a comment' and
'/* nor this */' stay exactly as written.
Can minifying change what a query does?
Not in normal cases, because only comments and whitespace outside of strings are removed. Exceptions are optimizer hints or MySQL /*! */ comments, which is why they are kept by default.
Does it execute my SQL?
No. It only scans the text character by character; there is no database and nothing is sent anywhere.
Why did I get an unterminated string error?
A quote, block comment or dollar-quote was opened but never closed. The message gives the line and column where it started.
Which dialect should I use for SQLite or MariaDB?
SQLite works with the generic setting; MariaDB uses the MySQL setting.
Related Tools
More like this: all Format & Validate tools, all Developer & Web tools or the TinySandy home page.