JustConvertAll-in-One Convert

SQL Minifier

Minify and compress SQL queries instantly online. Removes -- and /* */ comments, collapses whitespace, and produces a compact single-line query. Free — runs entirely in your browser.

Related Tools

Advertisement

SQL queries written for readability use newlines, indentation, and comments to document intent and structure complex joins, subqueries, and window functions. In production applications, however, these queries are often embedded as string constants in source code, configuration files, ORMs, or HTTP API payloads where multi-line strings are inconvenient or invalid. SQL minification removes comments and collapses whitespace to produce a compact single-line query string that is functionally identical to the formatted original.

Unlike JavaScript or CSS minification where size reduction directly impacts page load time, SQL minification is less about file size and more about compatibility and embedding convenience. Many database drivers, query builders, and configuration formats expect single-line SQL strings. Minified SQL is also easier to log on a single line, paste into a REPL, or include in a URL query parameter. The SQL database's query parser treats whitespace as insignificant, so there is no behavioral difference between formatted and minified SQL.

This tool removes -- single-line comments and /* */ block comments, then collapses all whitespace sequences (newlines, tabs, multiple spaces) to a single space. String literals and identifiers are preserved exactly — only whitespace outside of strings is modified. The output shows the percentage saved compared to the normalized input length.

Common Use Cases

Embedding SQL in application source code constants

Backend services often define complex analytical queries as string constants in Go, Java, or Python source files. Multi-line raw strings work in some languages but not others. Minifying the query to a single line makes it compatible with all string formats, easier to assign to a variable, and cleaner in code review when the query logic is already documented in a separate comment block or ADR.

Storing queries in JSON configuration files

Some applications load SQL queries from JSON configuration files (analytics platforms, reporting tools, data pipeline definitions). JSON does not support multi-line strings — newlines inside strings must be escaped as \n. Minifying the SQL first eliminates all literal newlines, producing a string that can be placed directly in a JSON value without escaping.

Including SQL in logging and monitoring output

Application performance monitoring tools (Datadog, New Relic, Splunk) capture slow query logs. When a query spans 30 lines, the log entry becomes hard to parse and search. Logging the minified SQL alongside the execution plan produces single-line, searchable query strings that can be correlated across log entries and filtered with standard log query tools.

Preparing queries for URL or API transmission

Some database management APIs and query endpoints accept SQL queries as URL query parameters or in JSON request bodies where special characters must be encoded. Minifying first reduces the number of characters that need percent-encoding (newlines become spaces, which are already a single character), producing shorter, cleaner request URLs.

How to Use

  1. Paste a formatted SQL query in the left panel.
  2. The minified output with comments removed appears instantly.
  3. Both -- single-line and /* */ block comments are stripped.
  4. Click "Copy Output" to copy the minified SQL.