Skip to content

SQL Minifier

Collapse multi-line SQL into a single line by removing -- and /* */ comments and extra whitespace.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is SQL Minifier?

This SQL minifier turns a nicely formatted, multi-line SQL query into a single compact line. It removes -- line comments and /* */ block comments and collapses indentation and line breaks into single spaces, so the query can be embedded in a string in your code, a JSON or YAML configuration value, a log message or a shell command.

Paste the query and the one-line version appears immediately, ready to copy. The clauses and their order are unchanged, so the query runs exactly as before.

How to use SQL Minifier

  1. Paste your multi-line SQL query into the Raw SQL Query box.
  2. The single-line version appears in the Inline Minified SQL box.
  3. Copy it into your code, configuration or command.
  4. Use the SQL Formatter to turn a one-line query back into a readable one.

Key features

  • Collapses multi-line SQL into one line
  • Removes -- and /* */ comments
  • Normalizes indentation and tabs
  • Instant output as you paste
  • Runs entirely in your browser

Common use cases

  • Embedding SQL queries as strings in application code
  • Putting queries in JSON, YAML or .env configuration values
  • Writing compact SQL in log messages and monitoring alerts
  • Passing queries to psql -c or mysql -e on the command line
  • Removing comments from SQL before sharing it

Technical details & standards

The minifier removes everything from -- to the end of a line, removes /* … */ blocks, and collapses all runs of whitespace, including line breaks and tabs, into a single space.

It works on the text rather than parsing SQL, so comment markers inside string literals are treated as comments too: a value such as 'a--b' or a URL in a string would be cut off. Check queries that contain such strings. Whitespace inside string literals is also collapsed, which matters only if the exact spacing of a stored value is important. Use parameterized queries rather than building SQL strings by hand.

Frequently asked questions

Does minifying SQL change how the query runs?

No. SQL ignores whitespace and comments between tokens, so the one-line query runs the same way. Check queries whose string literals contain -- or /*, because those would be treated as comments.

How do I turn a one-line SQL query back into a readable one?

Paste it into the SQL Formatter, which puts each clause on its own line and indents the conditions.

Why minify SQL at all?

Single-line SQL fits in code strings, configuration values and command-line arguments without escaping line breaks, and is easier to grep in logs.

Should I build SQL strings in my code?

Use parameterized queries or prepared statements instead of concatenating values into SQL. That prevents SQL injection and handles quoting for you.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More formatters & viewers tools

View all