Guide

Format SQL Online: Readable Queries and Risky Patterns

Short answer: to format SQL online, paste a query into the SQL Formatter and it puts each clause on its own line, indents conditions and uppercases keywords, or minifies the query to one line. It never changes what the query means, and a warnings panel flags common risky patterns. It does not validate SQL.

Before and after

This one-liner:

select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=1 and o.created_at>'2026-01-01' group by u.id,u.name order by orders desc limit 10

becomes:

SELECT
  u.id,
  u.name,
  count(o.id) AS orders
FROM users u
LEFT JOIN orders o ON o.user_id=u.id
WHERE u.active=1
  AND o.created_at>'2026-01-01'
GROUP BY u.id, u.name
ORDER BY orders DESC
LIMIT 10

SELECT, FROM, LEFT JOIN, WHERE and ORDER BY each start a line, and AND conditions are indented. Table and column names and the function count keep the case you wrote.

What it leaves alone

  • String literals, quoted identifiers and comments are never changed.
  • Spacing around operators and inside expressions is kept, so the meaning is identical.
  • Only recognised SQL keywords are uppercased.

Dialects

The dialect changes only how special text is read, never how the query is laid out: Generic, PostgreSQL (dollar-quoted strings and E'...' escapes), MySQL / MariaDB (backslash escapes and # comments), SQLite and SQL Server ([bracketed] names, nested comments in SQL Server) and BigQuery (triple-quoted and raw strings). Operators such as ::, ->, ->> and || are kept exactly as typed.

The warnings panel

It reports UPDATE or DELETE without WHERE, DROP, TRUNCATE, ALTER ... DROP, GRANT ALL, SELECT *, values joined into a query with + or left as ${...} or %s placeholders inside quotes, several statements on one line, and unclosed quotes or parentheses. Text inside strings and comments is ignored.

These checks are heuristic. They can miss problems, can flag harmless code (such as 'a' + col + 'b' in T-SQL) and cannot see how your application builds the query. Destructive statements such as DROP are the same kind of risk as in a shell command you should check before running. An empty list does not mean the query is correct or safe. Joined-in values are the classic route to SQL injection; see AI-generated code insecure patterns.

Format or minify

Format for reading and code review. Minify to put a query on one line; it removes comments, so keep the original if they matter.

How to format SQL online with the SQL Formatter

  1. Open the SQL Formatter.
  2. Paste your query and pick the dialect.
  3. Choose Format or Minify, the indent (2 spaces, 4 spaces or tab) and whether to uppercase keywords.
  4. Read the warnings, then copy or download the result.

Limits to know

  • General-purpose rules that suit standard SQL, MySQL and PostgreSQL.
  • Backslash escapes in strings (MySQL) are not interpreted; use doubled quotes.
  • It does not validate that the query is correct or safe to run.

Frequently asked questions

Does formatting change what the query does? No. Strings, names, comments and spacing inside expressions are kept.

Does the dialect change the layout? No, only how special text is read.

Does it validate SQL? No.

Why was SELECT * flagged? It is a common code-review warning; the list is heuristic.

Does minify remove comments? Yes.

Related tools and guides