Skip to content

SQL Minifier

Collapse a SQL query to one line and strip its comments.

Quick Tool Overview

The SQL Minifier collapses a query onto one line and strips both comment styles, while preserving whitespace inside string literals — because that is content, not formatting.

What it does
Collapses SQL to one line and removes comments
You give it
A formatted query or migration
You get back
A single-line statement that still runs
Best for
Embedding SQL in JSON, YAML, code or a shell command
Developer Tools Free, unlimited use No sign-up Runs in your browser

About the SQL Minifier

Sometimes a query has to become one line: pasting it into a JSON field, a YAML config, a shell command, a log message or a single-line string in code. The minifier collapses the whitespace, strips the comments and leaves a statement that still runs exactly as before.

The tokeniser is what makes that safe. Whitespace inside a string literal is content and is preserved; whitespace between tokens is formatting and is reduced to a single space, or removed entirely beside punctuation. A double-dash inside a string is not a comment, and a comment containing a quote does not unbalance the rest of the statement. Both comment styles are removed, which is usually the bigger saving on a query with a header block.

Key features of the SQL Minifier

String contents preserved

Two spaces inside a literal stay two spaces, because the tokeniser knows the difference between content and formatting.

Both comment styles removed

Double-dash and slash-star comments are stripped — and a double-dash inside a string is correctly left alone.

Punctuation spaced properly

No space before a comma or a closing bracket, one space between tokens, so the result reads as SQL rather than a jumble.

The saving in numbers

Size before and after and the percentage removed, which on a query with a header comment block can be substantial.

Reversible layout

Paste the result into the SQL Formatter to get a readable version back, though the comments are gone for good.

How to use the SQL Minifier

  1. 1

    Paste your SQL

    A formatted query, a migration or a stored procedure body.

  2. 2

    Minify

    Comments are stripped and the whitespace collapses to single spaces.

  3. 3

    Check the saving

    The stat row shows the size before and after and the percentage removed.

  4. 4

    Copy the one-liner

    Ready to paste into a config field, a log line or a code string.

Frequently asked questions

No. The database parses and plans the statement either way, and whitespace costs nothing measurable. Minify for the container the query has to fit into, not for speed.

Reviews of the SQL Minifier

What people who use the SQL Minifier think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the SQL Minifier. It takes half a minute and no account.

Write the first review

More developer tools