SQL Minifier
Strip SQL comments and collapse whitespace outside quoted literals, so a statement becomes one readable line without changing its value.
What the SQL Minifier does
Line comments run to the end of the line and block comments run to their closing */; both become a single space so two tokens never merge into one. Single quotes, double quotes and backticks are all treated as literals, and a doubled quote inside a literal is an escaped quote, not the end of it.
After the walk, spaces before a comma, semicolon or closing parenthesis are removed, because they carry no meaning there.
This changes layout only: it does not validate the statement, and it does not shorten identifiers or keywords. A comment between two tokens becomes one space, so a statement whose meaning depended on a comment — which no valid statement does — would change.
How to use it
Paste the statement into the SQL box, or press Run with the example already there.
Read the Minified SQL below: comments are gone and the statement is one line.
Check a quoted value in the Minified SQL with two spaces in it — both spaces survive, because whitespace inside a literal is data.
Worked example
Input:
SELECT id, name
FROM users -- trailing note
WHERE id = 'a b';
Output:
SELECT id, name FROM users WHERE id = 'a b';
Why it runs in your browser
The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.
One line of SQL, with comments removed and runs of whitespace collapsed — except inside a string literal, where two spaces are part of the value.
The page tracks quotes and comments as it walks the statement, so `--` inside a string is not a comment and `'a b'` keeps both spaces.
What it does, and what it does not
Line comments run to the end of the line and block comments run to their closing `*/`; both become a single space so two tokens never merge into one. Single quotes, double quotes and backticks are all treated as literals, and a doubled quote inside a literal is an escaped quote, not the end of it.
After the walk, spaces before a comma, semicolon or closing parenthesis are removed, because they carry no meaning there.
This changes layout only: it does not validate the statement, and it does not shorten identifiers or keywords. A comment between two tokens becomes one space, so a statement whose meaning depended on a comment — which no valid statement does — would change.
How to use SQL Minifier
Paste the statement into the SQL box, or press Run with the example already there.
Read the Minified SQL below: comments are gone and the statement is one line.
Check a quoted value in the Minified SQL with two spaces in it — both spaces survive, because whitespace inside a literal is data.
What to Expect
Best for
- Making a logged statement readable on one line
- Removing comments before pasting SQL into a log or a ticket
Not ideal for
- Formatting a statement for reading, which needs line breaks
- Validating SQL, which this page does not do
What this tool keeps
- Whitespace inside a quoted literal
- One space between tokens where a comment was
What may need cleanup
- Re-indent the statement if you want it readable
- A dialect-specific comment form is not recognised
Common errors
- The page refuses it: unterminated string starting at position
Example use cases
- Trimming a statement copied out of a slow-query log
- Preparing SQL for a single-line config value
Sample input
SQL: SELECT id, name …
Sample output
Minified SQL: SELECT id, name FROM users WHERE id = 'a b'; …
Who this is for
- Developers reading query logs
- Anyone pasting SQL into a one-line field
Frequently asked questions
Is whitespace inside quotes preserved?
Yes. A string literal is data, so 'a b' keeps both spaces. Only the text outside quotes is collapsed.
What happens to a block comment?
It becomes one space, so the tokens on either side stay separate. An unterminated block comment is refused with its position.
Does it reformat keywords?
No. Keyword case and identifier spelling are untouched; only comments and whitespace change.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.