1. Home
  2. Database
  3. SQL Minifier

SQL Minifier

Remove comments and extra whitespace to put SQL on one line, without touching strings or quoted names.

Runs in your browser

Minified SQL

Waiting for input.
Format it

What is the SQL Minifier?

Minified SQL is handy when a query has to live on a single line: in an environment variable, a YAML or JSON config file, a log message, a shell command or a code string. The SQL Minifier strips -- and /* */ comments and collapses every run of spaces, tabs and line breaks, keeping only the spaces SQL needs between words.

It reads the SQL the way a database does, so text inside quotes (including things that look like comments), quoted identifiers in "double quotes", `backticks` or [brackets], and PostgreSQL $$ strings are left exactly as written. It also never joins two minus signs into a comment.

How to use it

  1. Paste SQL, upload a .sql file or click Example.
  2. Choose whether to keep MySQL /*! */ hints and whether to put each statement on its own line.
  3. Copy or download the minified SQL.

Example

Input
-- Active users
SELECT id,
       name   -- display name
FROM   users
WHERE  status = 'active -- yes'
  AND  age >= 18;
Output
SELECT id,name FROM users WHERE status='active -- yes' AND age>=18;

Features

  • Comment removal. Strips -- line comments and /* block comments */, and # comments for MySQL if you choose.
  • String-safe. Quotes, quoted names and $$ strings are never changed.
  • Keeps hints. Optionally keeps MySQL /*! */ version hints and /*+ */ optimizer hints.
  • One statement per line. Useful for migrations and scripts that run line by line.
  • Size saved. Shows how many characters and bytes were removed.
  • Private. Runs in your browser; your SQL is never uploaded.

Frequently asked questions

Does minifying SQL make queries faster?

Not noticeably: databases ignore whitespace and comments when they parse a query. Minifying is about fitting SQL into one line or a smaller payload, not about speed.

Is it safe for stored procedures?

Yes for normal SQL, including PostgreSQL $$ function bodies. Be careful with scripts that rely on line breaks, such as SQL*Plus or psql meta-commands (lines starting with \ or /), and with DELIMITER changes in MySQL scripts.

What are MySQL /*! */ comments?

They are version hints: MySQL runs the code inside, while other databases treat it as a comment. mysqldump uses them a lot, so keep hints on when minifying a dump you will import into MySQL.

Last updated · Free, no sign-up, runs in your browser.

Free for everyone, kept free by you.

No paywall, no sign-up and no watermarks. If a tool saved you time, you can chip in any amount by UPI to keep Nova Free Tools running.

Esc
↑↓ move↵ openEsc close