Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

SQL Query Compressor & Shrinker

Paste SQL queries and instantly remove unnecessary whitespace, comments, and formatting to shrink file size

Your files never leave your browser
Input0 chars, 0 lines
Output0 chars, 0 lines
Ready·

Paste any SQL query, migration script, or stored procedure and strip it down to the smallest valid version — comments removed, whitespace collapsed, keywords properly spaced. Most files shrink 30–55% without changing how the query executes. And everything runs in your browser. Nothing gets uploaded.

How It Works

Paste SQL
→
Strip & Collapse
→
Compact Output

The tool first pulls out all string literals so they don't get mangled. Then it strips single-line comments (--) and block comments (/* */), collapses all whitespace into single spaces, and re-inserts the original strings untouched. SQL keywords get a space after them so the database can still parse everything properly.

Examples

Compressing a Commented SELECT Query

You have a well-documented query with inline notes that needs to fit into a REST API parameter.

INPUT
-- Get active users SELECT u.id, u.email, u.created_at FROM users u /* Only verified accounts */ WHERE u.status = 'active' AND u.verified = TRUE ORDER BY u.created_at DESC LIMIT 50;
OUTPUT
SELECT u.id, u.email, u.created_at FROM users u WHERE u.status = 'active' AND u.verified = TRUE ORDER BY u.created_at DESC LIMIT 50;

Shrinking a CREATE TABLE Statement

DDL scripts with indented column definitions and constraint comments — common in migration files.

INPUT
CREATE TABLE orders ( id SERIAL PRIMARY KEY, user_id INT NOT NULL, -- Total in cents amount DECIMAL(10, 2), status VARCHAR(20) DEFAULT 'pending', FOREIGN KEY (user_id) REFERENCES users(id) );
OUTPUT
CREATE TABLE orders (id SERIAL PRIMARY KEY, user_id INT NOT NULL, amount DECIMAL(10, 2), status VARCHAR(20) DEFAULT 'pending', FOREIGN KEY (user_id) REFERENCES users(id));

Multi-Statement INSERT Batch

Seed data scripts with blank lines between statements. The compressor handles multiple statements fine.

INPUT
INSERT INTO roles (name) VALUES ('admin'); INSERT INTO roles (name) VALUES ('editor'); INSERT INTO roles (name) VALUES ('viewer');
OUTPUT
INSERT INTO roles (name) VALUES ('admin'); INSERT INTO roles (name) VALUES ('editor'); INSERT INTO roles (name) VALUES ('viewer');

Who Uses This

👨‍💻 Backend Developers

Squeezing queries into config files, environment variables, or ORM raw strings with length limits.

🗄️ DBAs

Compacting migration scripts before deploying to production to minimize transfer size.

📊 Data Analysts

Pasting queries into tools like Metabase or Redash that choke on extra line breaks.

🔧 DevOps Engineers

Embedding SQL in shell scripts, CI pipelines, or Terraform provisioners where newlines cause headaches.

Common Mistakes

Forgetting that string literals with spaces are preserved

Some people worry the compressor will break strings like 'New York'. It won't. String literals are extracted before compression and put back exactly as-is afterward.

Expecting the output to be a valid one-liner for bash

Compressed SQL still has single quotes. If you're pasting it into a shell command, you need to handle quoting separately — wrap it in double quotes or escape the singles.

Compressing then trying to debug

Compressed SQL is hard to read. Keep the original formatted version in your codebase and only compress for deployment or storage. Don't compress your working copy.

Technical Details

Frequently Asked Questions

Does SQL compression change how my query runs?

No. The output is functionally identical to your input. Only whitespace and comments are removed — keywords, table names, values, and operators stay exactly the same. Any database engine will produce the same results from the compressed version.

How much smaller will my SQL file get?

It depends on how formatted your original is. Well-commented, nicely indented SQL typically shrinks 30–55%. If your SQL is already pretty compact, you might only see a 10–15% reduction. The tool shows you exact before-and-after byte counts.

Is it safe to compress stored procedures?

Yes. The compressor handles multi-statement SQL, including stored procedures, triggers, and functions. It correctly preserves string literals even when they contain characters that look like comments or whitespace. Just keep in mind that compressed procedural code is painful to debug later.

Does this tool upload my SQL to a server?

Nope. Everything happens in your browser tab using JavaScript. Your SQL is never transmitted anywhere. You can disconnect from the internet and it still works — try it yourself if you're skeptical.

Can I compress SQL for MySQL, PostgreSQL, and SQL Server?

Yes — the compressor is dialect-agnostic. It works on the text level, removing whitespace and comments regardless of which database you're targeting. MySQL-specific syntax, PostgreSQL extensions, T-SQL quirks — all handled the same way. The compressor doesn't validate SQL, it just shrinks it.

Share: