SQL Minifier
Collapse formatted SQL into compact text. Free, and runs entirely in your browser — nothing you enter is uploaded, stored or sent to a server.
About SQL Minifier
The opposite trip: a formatted query squeezed onto as few characters as SQL allows. That is worth doing when a query has to travel somewhere that counts characters — a configuration value, a URL, a JSON field, a dashboard definition, a log line that would otherwise wrap over twelve rows.
Comments go, because that is where most of the size is and none of the meaning. Whitespace goes wherever two tokens do not need separating, which is decided by what the tokens are rather than by a regular expression over the text — a-b and a - b mean the same thing and - -b does not.
What never goes is anything inside a string, a quoted identifier or a dollar-quoted block. Whitespace in those is data, and a minifier that collapsed it would change results rather than formatting. A line comment, if you keep comments, still forces a newline, because it would otherwise swallow the rest of the statement.
Where it helps
- Never collapses whitespace inside a string or a quoted identifier, where it is data rather than formatting.
- Decides spacing from what the tokens are, so operators do not run together into a different operator.
- Understands the dialect's comment and quoting rules, including MySQL # comments and PostgreSQL dollar quotes.
- Reports what it actually saved, which is the question a minifier is being asked.
- Can keep comments where they are part of the query — an optimiser hint, for example.
Limits
- It does not rewrite or optimise the query; it only removes characters that carry no meaning.
- A minified query is harder to read, which is the trade — keep the formatted original wherever it is the one being maintained.
- It cannot validate the SQL, so a query that was already broken stays broken and gets shorter.
Frequently asked questions
Is it safe to run the minified query?
It should behave identically: only whitespace between tokens is removed, and quoted content is untouched. The exception is a query that was already invalid, where there is no correct transformation to make.
Why does a comment still produce a line break?
Because a -- or # comment runs to the end of the line. Putting anything after it on the same line would comment that out too, so keeping comments means keeping the newline that ends them.
Does this make my query faster?
No. The database parses the query either way and the plan is identical. What it saves is characters in whatever is carrying the query around.
Related tools
- SQL Formatter — Format SQL statements with dialect selection
- Minifier — Shrink CSS, HTML or JavaScript
- Structure Minifier — Strip formatting from JSON, XML, YAML, TOML or TOON
- Gzip Compressor and Decompressor — Compress and expand gzip, zlib and raw deflate
- HTML Formatter — Indent and tidy HTML markup
- CSS Formatter — Format stylesheets with consistent indentation
More Web Development tools
- HTML Formatter — Indent and tidy HTML markup
- CSS Formatter — Format stylesheets with consistent indentation
- JavaScript Formatter — Re-indent JavaScript and TypeScript source
- SCSS/SASS Formatter — Format SCSS syntax and nested rules
- TypeScript Formatter — Format TypeScript source code
- SQL Formatter — Format SQL statements with dialect selection
- CSS Unit Converter — px, rem, em, percentages and viewport units, with a preview
- Query String Parser and Builder — Convert query strings into editable key-value data
- CSP Generator — Build a Content-Security-Policy, or check one, and write it for your server or framework
- CORS Generator — Write CORS configuration for nginx, Express, Go, Django, ASP.NET, Spring and more, and test an origin against it
- cURL Builder — Build an HTTP request and get it as curl, JavaScript, TypeScript, Go, Python, PHP, C#, Java and more
- Minifier — Shrink CSS, HTML or JavaScript
- Flexbox Playground — Try every flex property and read the CSS back
- CSS Grid Playground — Build a grid template and see the tracks it makes
- Responsive Viewport Tester — Render your markup at phone, tablet and desktop widths
- SVG Path Viewer — Draw path data and read back what it contains
- SVG to CSS Converter — Turn an SVG into a data URI for CSS or an img tag
- OAuth 2.0 / OIDC Helper — PKCE verifiers and challenges, state, nonce, and checking what came back
- Regex Tester — Test patterns, inspect groups and preview replacements
- User-Agent Parser — Identify the browser, engine, operating system and device behind a User-Agent string
- HTTP Status Codes — Look up what a status code means, when to send it, and whether it is cached or safe to retry
- HTML to JSX — Convert HTML and SVG markup into JSX for React, with styles, attributes and whitespace handled
- Semver Checker — Test versions against npm ranges, sort them by precedence, and see what each bump produces
- Cookie Parser and Builder — Read Set-Cookie and Cookie headers, check them against browser rules, and write one for your framework