Shipping an AI app or agent? Security review in 1 working day: $149 / ₹13,900. Request a review →
AI Review Ready
Home / Free tools / SQL formatter
Free tool · runs in your browser

SQL formatter beautify or minify

Paste a query. Format it into readable clauses, change keyword case, or squeeze it onto one line. Nothing leaves your browser.

What the formatter does

  • Starts each main clause on its own line: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, INSERT INTO, VALUES, UPDATE, SET, RETURNING, WITH, UNION.
  • Puts each selected column, each JOIN and each AND/OR condition on its own line, and indents subqueries and CTEs one level deeper.
  • Leaves strings, quoted names and comments exactly as typed. It changes layout and keyword case only, never the meaning of the query.
  • Minify removes comments and line breaks and keeps one space where SQL needs it. MySQL /*! … */ and optimizer /*+ … */ hint comments are kept because they change behaviour.

Why the dialect matters

The dialect only changes how quotes and comments are read, so the formatter never splits a quoted name or string:

DialectQuoted namesWorth knowing
Standard SQL / PostgreSQL"order"PostgreSQL folds unquoted names to lower case, so "Users" and Users are different tables. Dollar-quoted bodies ($$ … $$) and casts (::numeric) are kept intact.
MySQL / MariaDB`order`Double quotes are strings unless the ANSI_QUOTES SQL mode is on; # starts a comment.
SQL Server (T-SQL)[order] or "order"Double-quoted names need QUOTED_IDENTIFIER on (the default for most connections). Uses TOP or OFFSET … FETCH instead of LIMIT.
SQLite"order", also [order] and `order`Accepts the other databases' quote styles for compatibility.

Your SQL stays on your machine

The formatter is plain JavaScript in this page. Queries often contain table names, customer IDs or emails, so nothing is sent to a server; you can disconnect from the internet after the page loads and it still works.

Related: JSON formatter · XML formatter · diff checker · Postgres and Supabase security checks

Sources