Minify SQL

Remove nonessential SQL whitespace and comments without reordering clauses.

freeworks offlinenothing uploaded
ToolSQL Minifier
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Comments and formatting whitespace are removed between SQL tokens while strings, identifiers, numeric literals, and required separators remain. The pass does not optimize execution plans.

  • Whitespace outside quoted values is usually insignificant.
  • Clause order remains unchanged.

Worked example

Minify SELECT Query
Remove unnecessary whitespace and comments from a SQL query
Input
											SELECT
  name,
  email
FROM
  users
WHERE
  active = true
  -- only active users
  AND age > 18;
										
Output
												SELECT name, email FROM users WHERE active = true  AND age > 18;
											

When to use this

Embedded queries, telemetry payloads, and generated migrations minify SQL.

Edge cases

  • Whitespace inside a string is data.
  • Removing the newline after a double-dash comment changes its scope.
  • Adjacent keywords need a separator.

References