$ sql --format

sql formatter.

Format and beautify SQL queries with syntax highlighting. 100% client-side.

0 chars
0 chars
1
-- Click Format to beautify
The tool supports MySQL, PostgreSQL, SQLite, and standard SQL. Keywords and functions are highlighted based on common SQL syntax.
Yes, CTEs (WITH clauses), subqueries, JOINs of all types, and window functions are properly formatted with correct indentation.
Yes, click the "Minify" button to collapse the query into a single line, useful for embedding in application code.

Why Format SQL?

Unformatted SQL from ORMs, logs, or generated queries is often unreadable. Proper formatting makes queries auditable, debuggable, and team-friendly. A single long-line query can hide expensive full table scans or missing JOIN conditions.

Formatting Conventions

ElementStyleExample
KeywordsUppercaseSELECT, FROM, WHERE, JOIN
Table aliasesShort, lowercaseusers u, orders o
Indentation2 spaces per levelNested subqueries
Comma placementLeading (before), column2
JOINsOwn line eachJOIN orders o ON ...

Before & After

-- Before: unreadable
SELECT u.name,o.total,o.date FROM users u JOIN orders o ON u.id=o.user_id WHERE o.total>100 AND o.date>'2024-01-01' ORDER BY o.total DESC

-- After: clear structure
SELECT
  u.name,
  o.total,
  o.date
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE o.total > 100
  AND o.date > '2024-01-01'
ORDER BY o.total DESC

Performance tip: Always run EXPLAIN or EXPLAIN ANALYZE on formatted queries. A well-formatted query is much easier to read in the execution plan output.

learn more in our detailed guide.

→ read the guide