SQL Minifier
Compress SQL queries by removing comments and collapsing whitespace while safely preserving string literals.
How to Use
Compress SQL queries by removing comments and collapsing whitespace while preserving the exact meaning of your query. String literals and quoted identifiers are never modified.
- Paste SQL: Enter your formatted SQL query into the input panel. Multi-statement scripts with semicolons work too.
- Configure options: Toggle comment removal, whitespace collapsing, and trailing semicolon removal independently.
- Review stats: The statistics panel shows original size, minified size, bytes saved, and reduction percentage in real time.
- Copy result: Click the copy button to grab the minified SQL for use in your application logs, API payloads, or code strings.
About This Tool
Safe Tokenizer-Based Minification
Unlike regex-based minifiers that can accidentally strip whitespace inside string literals, this tool uses a proper tokenizer. The SQL is split into discrete tokens — string literals (single quotes with escaped '' sequences), double-quoted identifiers, backtick identifiers (MySQL), PostgreSQL dollar-quoted strings ($$...$$), single-line comments (--), block comments (/* */), whitespace runs, and code tokens. Only whitespace and comment tokens are modified; string literals pass through untouched. This guarantees the minified output is semantically identical to the input.
SQL Comment Styles
SQL supports two comment styles defined in the ISO SQL standard. Single-line comments start with two dashes (--) and extend to the end of the line — commonly used for inline annotations. Block comments use /* ... */ delimiters and can span multiple lines — often used for section headers or temporarily disabling query blocks. Both styles are recognized and removable by this tool, while the content inside string literals that happens to look like comments is always preserved.
Use Cases for Minified SQL
Minified SQL is essential for application logging where multiline queries break structured log parsers like ELK Stack or Datadog. ORM query logging in frameworks like Django, Rails, and Hibernate often produces heavily formatted SQL that becomes unreadable in log aggregators. Minification also reduces payload size when SQL is transmitted over HTTP APIs (common in database-as-a-service platforms), fits queries into character-limited fields in monitoring dashboards, and makes SQL strings more manageable when embedded directly in application code.
Why Use This Tool
Instant, Private SQL Processing
SQL queries often contain sensitive information — table names reveal your schema, WHERE clauses expose business logic, and string literals may contain actual data values. This tool processes everything entirely in your browser using a JavaScript tokenizer. No SQL is ever transmitted to any server, making it safe for production queries, internal schemas, and queries containing customer data references.
The real-time statistics panel helps you quantify the space savings — typical formatted SQL with comments achieves 40-70% size reduction when minified.