SQL Minifier

Minify SQL by stripping comments and collapsing insignificant whitespace while keeping every string literal and quoted identifier byte-for-byte, locally in your browser.

  • Runs locally in your browser
  • No upload required

Capabilities

  • Download result

Try it

Processed entirely in your browser; never uploaded.

Each dialect has its own comment, string and identifier rules.

Minified size
37 characters
Removed
27 characters
SELECT id,name FROM users WHERE id=1;

Supported formats

Input
text/plain
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Minified SQL from 64 to 37 character(s).

How it works

  • Tokenised the SQL, keeping literals and identifiers opaque.
  • Removed comment and whitespace tokens.
  • Re-joined the tokens with a space only where it is required.
  • String literals and quoted identifiers are preserved byte-for-byte.

Methodology

  1. Tokenise the SQL, keeping literals, quoted identifiers and comments opaque.
  2. Drop comment and whitespace tokens.
  3. Re-join the remaining tokens, inserting a single space only where two tokens would otherwise merge into a different token.

Usage

  1. Paste SQL that may contain comments or extra whitespace.
  2. Choose the dialect so the right comment syntax is recognised.
  3. Run the minifier and copy the compact statement.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Comment and whitespace removal

jsonSelect to copy
{
  "text": "-- fetch the users\nSELECT   id , name\nFROM users   WHERE id = 1;",
  "dialect": "standard"
}

A value containing a comment marker

jsonSelect to copy
{
  "text": "SELECT '-- not a comment'   AS note;",
  "dialect": "postgresql"
}

MySQL hash comment

jsonSelect to copy
{
  "text": "SELECT id # trailing note\nFROM users;",
  "dialect": "mysql"
}

Limitations

Smaller without being wrong

Removing a comment is safe; removing the space between two keywords is not. The minifier decides where a space is required by looking at the tokens either side.

Frequently asked questions

Does it change my string values?
No. Single- and double-quoted contents are copied exactly, including spaces and comment markers.
Can I minify a whole script?
Yes. Every statement is minified in one pass; statement separators are preserved.
Is my SQL uploaded?
No. The statement is processed entirely in your browser.

Sources

  1. ISO/IEC 9075-1:2023: Information technology, Database languages SQL — ISO/IEC
  2. PostgreSQL Documentation: SQL Syntax, Lexical Structure — PostgreSQL Global Development Group
  3. MySQL 8.0 Reference Manual: String Literals — Oracle
  4. SQLite Documentation: SQL Syntax — SQLite Consortium
  5. Microsoft Learn: Transact-SQL Syntax Conventions — Microsoft