SQL Query Compressor & Shrinker
Paste SQL queries and instantly remove unnecessary whitespace, comments, and formatting to shrink file size
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
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.
-- 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;
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.
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)
);
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.
INSERT INTO roles (name)
VALUES ('admin');
INSERT INTO roles (name)
VALUES ('editor');
INSERT INTO roles (name)
VALUES ('viewer');
INSERT INTO roles (name) VALUES ('admin'); INSERT INTO roles (name) VALUES ('editor'); INSERT INTO roles (name) VALUES ('viewer');
Who Uses This
Squeezing queries into config files, environment variables, or ORM raw strings with length limits.
Compacting migration scripts before deploying to production to minimize transfer size.
Pasting queries into tools like Metabase or Redash that choke on extra line breaks.
Embedding SQL in shell scripts, CI pipelines, or Terraform provisioners where newlines cause headaches.
Common Mistakes
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.
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.
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
- Processing: 100% client-side — JavaScript only, no server calls
- Browser Support: Chrome, Firefox, Safari, Edge
- Input Limit: No hard limit — tested with files over 1 MB
- Preserves: String literals, keyword spacing, semicolons
- Removes: Single-line comments, block comments, extra whitespace, blank lines
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.