Categories
SQL Minifier
Minify SQL by removing unnecessary whitespace, line breaks, and comments.
Overview
Compresses readable, formatted SQL or SQL with comments into a single line by removing unnecessary whitespace, line breaks, and comments.
This is the reverse of SQL Formatter, and is useful when you want to handle SQL in a compact form, such as embedding it in a configuration file or log.
The contents of string literals (enclosed in '...' or "...") are preserved as-is, so data is never broken unintentionally.
Usage
- 1
Enter the SQL you want to minify into the text area.
- 2
Click the "Minify" button.
- 3
A single line of SQL with unnecessary whitespace, line breaks, and comments removed is displayed.
Example
Input
SELECT id, name -- fetch users FROM users WHERE age > 18
Output
SELECT id, name FROM users WHERE age > 18
Use Cases
Compressing formatted SQL with comments, written during development, into one line before embedding it in application code or logs
Saving a long SQL query as a single-line value in a configuration file or environment variable
Making SQL compact before pasting it somewhere line breaks are awkward to handle, such as chat or a commit message
FAQ
Is whitespace inside string literals removed too?
No. The contents of string literals enclosed in '...' or "..." are preserved as-is.
Are comments removed as well?
Yes. Both -- line comments and /* */ block comments are removed.
How is this different from SQL Formatter?
SQL Formatter makes SQL readable, while SQL Minifier does the opposite: it removes unnecessary whitespace, line breaks, and comments to compress it.
Notes
Whitespace and line breaks inside string literals are preserved. Only whitespace, line breaks, and comments that are unnecessary as SQL syntax are removed.
Both -- line comments and /* */ block comments are removed.
The minified result is less readable. For reading it back later or for review, we recommend using SQL Formatter instead.