SQL Minifier

Formatters

How to use the SQL Minifier

Minify your SQL in three steps:

1

Paste your SQL

Paste a formatted or multi-line SQL query — with comments and indentation — into the input box. You can also upload a .sql or .txt file.

2

Click Minify SQL

Press the Minify SQL button. All -- and /* */ comments are stripped and all whitespace is collapsed to single spaces, producing a compact single-line query.

3

Copy or download

Click Copy to send the minified SQL to your clipboard for immediate use, or Download to save it as a .sql file.


When to use this tool

Use the SQL minifier to reduce query size and strip comments for production use:

  • Embedding SQL queries as string literals in application source code without formatting overhead
  • Storing SQL in environment variables, config files, or JSON where newlines cause parse errors
  • Reducing SQL payload size in API requests and GraphQL queries that pass raw SQL
  • Stripping development comments from SQL before deploying to production environments
  • Compressing SQL scripts for transmission over bandwidth-constrained connections
  • Removing inline query hints and comments before logging queries to prevent information leakage
  • Preparing SQL for comparison or diffing where whitespace differences create false changes

Frequently asked questions

Q:What types of comments are removed during minification?
Both SQL comment styles are removed: single-line comments starting with -- (and everything after them until the end of the line) and multi-line block comments enclosed in /* and */. This includes inline comments that appear mid-query after a clause.
Q:Will minifying SQL break my query or change its behaviour?
No — removing whitespace and comments never changes SQL semantics. The query will execute identically on the database server. SQL parsers treat any amount of whitespace as equivalent to a single space, so collapsing it has no functional effect.
Q:Does it preserve whitespace inside string literals?
The current implementation uses regex-based whitespace collapsing which may affect whitespace inside quoted string values (e.g. WHERE name = 'John Doe'). If your query contains string literals with intentional multiple spaces, review those after minification.
Q:Can I use this to remove only comments without collapsing whitespace?
The current tool combines both operations (comment removal and whitespace collapsing) into a single minification step for maximum compression. If you need only comment removal while preserving formatting, use our SQL Formatter tool which re-formats cleanly after parsing.
Q:Is there a query length limit?
No — the minifier runs entirely in your browser and processes text using JavaScript string operations. It handles queries of any length without a server-side size limit, though very large queries (multi-megabyte) may take a moment on slower devices.
Q:How much size reduction can I expect?
Reduction varies depending on how much whitespace and how many comments your original SQL contains. Heavily commented and indented queries can shrink by 40–70%. A tightly written query with minimal comments might only reduce by 10–20%. The stats panel shows exact before/after sizes and the percentage saved.