SQL Minifier
About this tool
About SQL Minifier
Need a query on one line for a JSON config, an environment variable, a Java or Python string, or a log search? Paste it here and every comment, line break and run of spaces disappears, leaving a single compact line. The minifier reads SQL the way a database does: text inside single quotes, double-quoted and backtick identifiers, SQL Server [bracket] names and PostgreSQL $$ function bodies are copied byte for byte, so a string like 'a -- b' is never mistaken for a comment. Optimizer hints written as /*+ ... */ and MySQL /*! ... */ comments are kept because they change how the query runs. Spaces are only removed next to commas, parentheses, semicolons and comparison operators, and two minus signs are never joined into a comment. The saving in bytes is shown. Switch Mode back to Format at any time to pretty-print the query for one of 20 SQL dialects. It runs in your browser, so queries are never uploaded.
Built and maintained by Abhi JainUpdated
How to Minify SQL
- 1
Paste your SQL
Paste one or more statements into the SQL pane or open a .sql file.
- 2
Check the result
The one-line version appears on the right with the bytes saved.
- 3
Copy it
Copy the minified SQL or download it as a file.
SQL Minifier: questions and answers
Does minifying SQL make it run faster?
No. Databases ignore whitespace and comments when they parse a query, so execution time is the same. Minifying helps when the query has to fit on one line or be embedded in a string.
Are comments inside strings removed?
No. Anything between quotes is copied exactly, so '-- not a comment' stays in the string.
Why are some comments kept?
Comments that start with /*+ are optimizer hints in Oracle, MySQL and others, and /*! comments are executed by MySQL. Removing them could change how the query runs.
Can I turn minified SQL back into readable SQL?
Yes. Switch Mode to Format, choose your dialect, and the query is laid out on multiple lines again. Removed comments cannot be restored.
More SQL Formatter presets
Related tools
- JSON FormatterBeautify, minify and validate JSON with exact error locations, without changing a single value.
- YAML Formatter & ValidatorValidate YAML with line and column errors, re-indent it and keep comments.
- XML FormatterPretty-print, minify and validate XML with line and column errors.
- JavaScript FormatterBeautify minified JavaScript, or minify it safely by removing comments and whitespace.