SQL Minifier
Minify SQL: remove comments and collapse whitespace into a compact single line, without touching strings or quoted identifiers. Handy for logs, code and configs.
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the SQL Minifier
- 1 Paste your SQL.
- 2 Choose whether to keep comments.
- 3 Copy the compact SQL.
About the SQL Minifier
Sometimes you need a query on a single line: in a string in your code, a configuration file, a CSV, a log search or a command-line call. The SQL minifier removes comments and turns every run of spaces, tabs and line breaks into one space, and drops spaces around commas, parentheses and semicolons.
It reads the query character by character and leaves everything inside quotes alone: 'string literals', "double-quoted identifiers", `MySQL backticks` and [SQL Server brackets] are copied exactly, including their spaces. Escaped quotes such as 'it''s' are handled correctly.
Comments are removed by default. MySQL version comments (/*! … */) and optimizer hints (/*+ … */) are kept because they change how the query runs. If you keep line comments, each ends with a line break, since otherwise the rest of the query would become part of the comment.
Frequently asked questions
Does minifying change the result of my query?
No. Whitespace and comments have no effect on what a query does, and quoted text is never changed.
Why are some comments kept?
/*! … */ comments are executed by MySQL and /*+ … */ comments are optimizer hints in Oracle and MySQL, so removing them could change the query's behaviour.
Can I make minified SQL readable again?
Yes, paste it into the SQL formatter.
Does it work for every database?
Yes, it only handles whitespace, comments and quotes, which work the same in all common SQL dialects.