SQL Formatter & Minifier

Pretty-print SQL with one clause per line, upper-case keywords and indented subqueries, view it with syntax highlighting, or minify it onto a single line.

Input SQL

Why format SQL?

Queries copied from application logs, ORMs or monitoring tools usually arrive as one long line, and hand-written SQL drifts into a mix of cases and indent styles. Laying a query out one clause per line makes joins, filters and grouping easy to review, and makes a diff of two versions much smaller. This formatter reads your SQL, splits it into tokens (keywords, identifiers, strings, numbers, operators and comments) and rebuilds it with a consistent layout. Minify does the opposite and packs a query onto one line for embedding in code, a config file or a command.

How to use it

  1. Paste one or more statements into Input SQL, or click Sample SQL to load three example queries: a SELECT with a join, subquery and GROUP BY, an INSERT … SELECT, and an UPDATE with a CASE expression.
  2. Click Format. The result appears under Formatted SQL with keywords, functions, strings, numbers and comments in different colours.
  3. Click Minify instead to strip comments and collapse whitespace into a single line.
  4. Check the stats line: number of lines, number of characters and the size ratio compared with your input.
  5. Click Copy Output to copy the plain text (no colours), or Clear to empty both input and output.

Formatting rules

Limitations

The formatter is rule-based and does not parse SQL grammar, so it never reports syntax errors. The AND in BETWEEN x AND y is moved to its own line like a logical AND, and commas inside function calls also cause line breaks. Column names that happen to be keywords (for example date, year or first) are upper-cased; unquoted identifiers are case-insensitive in most databases, but check if you rely on exact case. Dialect-specific syntax such as PostgreSQL dollar-quoted function bodies or named parameters written as :name may not be laid out cleanly. Formatting and minifying run entirely in your browser with plain JavaScript: queries are not sent to a server and nothing is stored.

Frequently asked questions

Which SQL dialects does it support?

It handles the syntax shared by MySQL, PostgreSQL, SQLite, SQL Server and Oracle: SELECT, INSERT, UPDATE, DELETE, joins, CTEs with WITH, window functions with OVER and PARTITION BY, and CASE. Vendor extensions are passed through but may not get special layout.

Can formatting change what my query does?

It is designed to change only whitespace and keyword case. Strings and quoted identifiers are never touched, and a -- comment always stays on its own line so it cannot swallow the code that follows. Still, review the output before running it against a production database.

What does Minify remove?

Comments (both -- and /* */) and extra whitespace between tokens. Text inside quotes, including runs of spaces, is kept exactly as written.

Is my SQL uploaded or logged?

No. The page does all the work locally, so it is safe for queries that contain table names or sample values you would rather not share. Nothing is saved in your browser either.

Related tools