$ 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
| Element | Style | Example |
|---|---|---|
| Keywords | Uppercase | SELECT, FROM, WHERE, JOIN |
| Table aliases | Short, lowercase | users u, orders o |
| Indentation | 2 spaces per level | Nested subqueries |
| Comma placement | Leading (before) | , column2 |
| JOINs | Own line each | JOIN 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