Free SQL Minifier

Paste SQL and get a compact version: comments and extra whitespace are removed while strings, quoted identifiers, operators and optimizer hints stay exactly as they were. Choose your database, and see how many bytes you saved. Everything runs in your browser.

100% Client-Side Processing: Your SQL is minified directly in your browser. Nothing is sent to a server.

Dialect decides how quotes and comments are read: 'strings', "identifiers", -- and /* */ comments; MySQL #, PostgreSQL $$ or [bracket] syntax asks you to pick a dialect.

0 characters

Comments and extra whitespace are removed; string literals, quoted identifiers, operators and keywords are kept as they are. The result is re-read with the chosen dialect's rules and your SQL is shown unchanged if any token differs, so pick the dialect your database uses.

What Gets Removed

  • โ€ข Multi-line comments (/* */), except hints if you keep them
  • โ€ข Single-line comments (-- and MySQL #)
  • โ€ข Line breaks, indentation and spaces that are not needed

What Gets Preserved

  • โ€ข String literals, including -- and ; inside them
  • โ€ข Quoted identifiers such as "my col", `my col` and [my col]
  • โ€ข PostgreSQL $$ function bodies and operators such as @@, <-> and #-
  • โ€ข Client commands on their own line: T-SQL GO and SQLCMD :setvar / :r, MySQL DELIMITER, psql \set / \copy, SQL*Plus commands (SET, PROMPT, SPOOL, @script) and /
  • โ€ข COPY ... FROM stdin data rows from pg_dump files, byte for byte (tabs included)
  • โ€ข Keyword case, table and column names

How to minify SQL online, free and without uploading

To minify SQL, paste your query into the Input SQL box, or click Load Sample. The Minified SQL box appears as you type, with comments and extra whitespace removed. Pick your Dialect, tick or untick Keep optimizer hints and One statement per line, then click Copy, or Download to save minified.sql. The built-in sample, 790 bytes with three comments, becomes 531 bytes, a 32.8% reduction, and the Comments Removed panel shows 3.

It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). The minifier is a script that ships with the page, and it never connects to a database. There is no account and nothing to install.

SQL minification strips what a database does not need: comments, line breaks and indentation. The query means the same afterwards, and the tool checks it by re-reading its own output and falling back to your original text if any token differs. A database reads whitespace in a moment, so do not expect a faster query; expect a shorter string to store or embed. To read a compact query again, use the SQL formatter.

Table of Use: what the minifier removes and keeps

SQL pasted in, the minified result and a note, with Standard SQL as the dialect unless stated
SQL you pasteMinified outputNote
SELECT a, b FROM t -- tail WHERE x = 'a -- b; c'SELECT a,b FROM t WHERE x='a -- b; c'The comment goes; the -- and ; inside the string stay
SELECT /*+ INDEX(t idx) */ a FROM tSELECT /*+ INDEX(t idx) */ a FROM tThe hint is kept while Keep optimizer hints is ticked
SELECT /*+ INDEX(t idx) */ a FROM tSELECT a FROM tUntick Keep optimizer hints and it is removed
WHERE x = -1 AND y > - 2WHERE x=-1 AND y>-2Spaces are dropped where the result cannot be read differently
where x = 'a b'where x='a b'Spaces inside a string are never touched
select `my col`, "x y", [z w] from t (SQLite)select `my col`,"x y",[z w] from tQuoted identifiers are kept as they are
SELECT a FROM t; SELECT b FROM u; (One statement per line ticked)SELECT a FROM t; SELECT b FROM u;Unticked, the statements follow each other on one line
select 1 GO select 2 (SQL Server)select 1 GO select 2GO is a client command and stays alone on its line
select a from t # c (Standard SQL)select a from t # cShown unchanged with a prompt to choose MySQL / MariaDB or PostgreSQL

Features

  • Comments and whitespace removed. Line comments (-- and MySQL #), /* */ block comments, line breaks and indentation go. Keyword case, table names and column names are not changed.
  • Strings and quoted names protected. Literals, "double-quoted", backtick and [bracket] identifiers, PostgreSQL $$ bodies and operators such as @@ and <-> are kept intact.
  • Optimizer hints kept. Keep optimizer hints (/*+ ... */) and MySQL /*! ... */ comments is ticked by default.
  • One statement per line. Optional, so a script stays easy to scan after minifying.
  • Six dialects. Standard SQL, MySQL / MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle and SQLite, with a Switch dialect button when your SQL looks like another database.
  • Client commands preserved. T-SQL GO, SQLCMD lines, MySQL DELIMITER, psql backslash commands, SQL*Plus lines and COPY ... FROM stdin data rows stay exactly where they are.
  • Savings at a glance. Original Size and Minified Size in KB and bytes, Size Reduction as a percentage, and Comments Removed.
  • Warnings. An unclosed quote or comment is reported with its line number.

How to use the SQL minifier

  1. Paste your SQL into the Input SQL box, or click Load Sample. Click Clear All to start again.
  2. Choose your database in the Dialect list so its quotes and comments are read correctly.
  3. Leave Keep optimizer hints (/*+ ... */) and MySQL /*! ... */ comments ticked unless you want hints removed.
  4. Tick One statement per line if you are minifying a script.
  5. Read the Minified SQL box and the Original Size, Minified Size, Size Reduction and Comments Removed panels.
  6. Click Copy, or Download to save the .sql file.

Who can use it

  • Application developers embedding a query in code or a config file, who can also shrink the surrounding files with the JavaScript minifier, the CSS minifier and the HTML minifier.
  • Database administrators compacting migration scripts and dump files before they are stored or sent, and comparing before and after in the text diff tool.
  • API and tooling authors who pass SQL inside JSON, with the JSON minifier for the rest of the payload.
  • Support engineers pasting a query into a ticket or a log line on a single line, and counting its size with the character counter.
  • Reviewers who need the readable version back and use the SQL formatter, then clear stray blank lines in other text with the remove empty lines tool.

FAQs

How do I minify SQL online?

Paste your query into the Input SQL box, or click Load Sample. The Minified SQL box appears as you type, with comments and extra whitespace removed. Pick your Dialect, then click Copy or Download to save minified.sql. The four panels below show the original size, the minified size, the percentage saved and the number of comments removed.

Does minifying change what my query does?

No, the query logic stays the same. Only comments and the whitespace between tokens are removed. Keywords, identifiers, operators, strings and quoted names are kept exactly, and the minifier re-reads its output and shows your SQL unchanged if any token differs. One caveat: SQLite names an un-aliased result column after its exact text, so give computed columns an AS alias.

Will minified SQL run faster?

Not in any meaningful way. A database reads whitespace and comments in a moment, so the query itself runs the same. The benefit is a shorter text to store, send or embed, for example a query held in a code string, a config file, a log line or a migration script.

Which comments are removed and which are kept?

Line comments (-- and MySQL #) and /* */ block comments are removed. Optimizer hints that start with /*+ and MySQL executable comments that start with /*! are kept by default, because they can change how a query runs. Untick Keep optimizer hints (/*+ ... */) and MySQL /*! ... */ comments to remove those too.

Can I minify several statements at once?

Yes. Paste a whole script and every statement is minified. Semicolons inside strings and comments do not end a statement. By default the statements follow each other on one line; tick One statement per line to start each statement on its own line, which keeps long scripts easier to scan.

Why am I asked to choose a dialect?

Databases read quotes and comments differently. A MySQL # comment, [bracket] identifiers or PostgreSQL $$ quoting could be misread as Standard SQL and swallow part of the query. When the minifier spots such syntax it shows your SQL unchanged with a Switch dialect button. Click it, or choose the dialect yourself.

Is my SQL uploaded anywhere?

It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). The minifier is a script that ships with the page, so queries with real table names or values stay on your device. There is no account, and the tool never connects to a database.