SQL Minifier: Free Online Tool
FREE TOOL · NO SIGN-UP
This SQL minifier compresses SQL queries and scripts into a single compact line by removing comments, line breaks and extra spaces, while leaving string literals and quoted identifiers exactly as they were. Use it to embed queries in application code, config files, JSON payloads or logs, or to shorten long scripts before sharing them. Paste your SQL, and the minified version appears instantly with the percentage saved. It runs entirely in your browser, so queries with table names or data never leave your device.
How to Use the SQL Minifier
One box, one option, and a result panel.
Step 1: Enter or paste your input
Paste a query or a script into the SQL box. It can be a single SELECT, a long report query with joins and CTEs, or several statements separated by semicolons. Clear empties the box.
Step 2: Choose your options
Tick Uppercase keywords if you want common SQL keywords like SELECT, FROM, WHERE, JOIN, GROUP BY and ORDER BY converted to capitals in the output. Leave it unticked to keep your original casing. Table and column names are never changed.
Step 3: Copy, download or apply the result
The minified SQL updates as you type. The stats show the percentage saved and the input and output character counts. Use Copy to grab it, or Download to save it as query.min.sql. Test the minified query against a development database before using it in production.
What SQL Minification Removes
An SQL minifier strips everything the database does not need to run the query: comments, line breaks, indentation and spaces that are not required between words. The result is functionally the same query in fewer characters.
Specifically, this tool removes:
- Single-line comments starting with
--. - Block comments between
/*and*/. - Line breaks and tabs.
- Spaces around symbols such as commas, brackets,
=,<>and*.
It keeps a single space wherever one is needed, which is between two words, numbers or strings. So this:
SELECT id, name
FROM users -- active only
WHERE status = 'active';
becomes:
SELECT id,name FROM users WHERE status='active';
Multi-character operators like <>, <=, >=, !=, :: and || stay together. Statement separators (semicolons) stay in place, so multi-statement scripts still split correctly.
Comments, Whitespace and String Literal Safety
The main risk with minifying SQL is damaging text that only looks like code. This minifier reads strings and quoted names as whole units first, so nothing inside them is touched:
- Single-quoted strings like
'it''s -- fine'keep their spaces, dashes and doubled quotes. - Double-quoted identifiers like
"Order Date"keep their spaces. - Backtick identifiers used in MySQL, like
`user name`, are preserved.
That means WHERE note = 'call -- later' will not be cut off at the dashes.
Removing line breaks is the reason comments must go. A -- comment runs to the end of the line, so if the line break disappeared and the comment stayed, it would swallow the rest of the query. Stripping comments first makes single-line output safe.
There are two exceptions to keep in mind. MySQL # comments are not recognized, so convert them to -- before minifying. And all block comments are removed, including MySQL /*! ... */ version comments and optimizer hints such as Oracle /*+ INDEX(...) */. If your query relies on hints, add them back after minifying.
Minify vs Beautify: When to Use Each
Minifying and beautifying are opposites, and both are useful at different times.
| Minify | Beautify | |
|---|---|---|
| Output | One compact line | Indented, one clause per line |
| Comments | Removed | Kept |
| Best for | Embedding in code, configs, JSON, URLs, logs | Reading, reviewing, debugging, documentation |
| Tool | This SQL minifier | SQL Formatter |
Keep the readable version as your source in version control and minify only the copy that goes into a string or payload. If you receive a minified query and need to understand it, paste it into the SQL Formatter to expand it again.
Minification does not make queries run faster on the database. The query planner ignores whitespace and comments. The gains are smaller payloads, tidier embedded strings and single-line log entries.
Dialect Notes for MySQL, PostgreSQL and SQL Server
The minifier works on standard SQL syntax, which covers most everyday queries in every major database. A few dialect details are worth knowing:
- MySQL / MariaDB: backtick identifiers and
--comments are handled. Convert#comments first, and note that/*! */version comments are removed. MySQL requires a space after--for a comment, which matters only in your source, not the output. - PostgreSQL: the
::cast operator and||concatenation stay intact. Dollar-quoted function bodies ($$ ... $$) are not treated as strings, so their contents are minified like normal SQL. Check function definitions carefully. - SQL Server: square bracket identifiers like
[Order Date]are not protected, so spaces inside them are removed. Use double quotes for names with spaces.GObatch separators need their own line, so remove them or run batches separately. - SQLite: standard syntax works as expected.
Key Features of Our SQL Minifier
- Free with no signup.
- Removes comments, line breaks and extra spaces in one pass.
- String-safe: quoted strings and identifiers are preserved.
- Optional keyword uppercasing.
- Savings shown as a percentage with character counts.
- Copy and Download (.sql) buttons.
- Private: runs in your browser.
Who Minifies SQL
- Backend developers embedding queries in code or ORM raw strings.
- Data engineers placing SQL in JSON, YAML or pipeline configs.
- Analysts sharing queries in chat or tickets.
- DevOps teams keeping logs to one line per query.
- App builders sending SQL through APIs with size limits.
Pro Tips and Mistakes to Avoid
Checklist of best practices
- Keep a formatted, commented copy as your source.
- Test the minified query before deploying it.
- Use parameters or placeholders instead of pasting real data into queries.
- Check that the last statement ends with a semicolon if your tool needs it.
Common mistakes and quick fixes
- Lost optimizer hints. Block comments are stripped. Re-add hints after minifying.
- MySQL
#comments. Change them to--first. - SQL Server bracket names with spaces. Switch to double quotes.
- Expecting faster queries. Use indexes and query plans for speed, not minification.
Ship Leaner Queries
Paste your SQL above to compress it in one step. Expand queries again with the SQL Formatter, compress front-end code with the JavaScript Minifier and CSS Minifier, and tidy data with the JSON Formatter. Browse all free tools in the FHSEO Hub tools directory.
