Sql Formatter
Result
| Formatted SQL |
|---|
Share on Social Media:
SQL Formatter — Turn Query Spaghetti into Readable SQL
ORMs, log files, and legacy codebases all produce the same thing: 400-character single-line SQL that no human can review. This free SQL formatter restructures any query with proper indentation, one clause per line, consistent keyword casing, and aligned subqueries — instantly, in your browser, with nothing uploaded. It supports MySQL, PostgreSQL, SQL Server, Oracle, and SQLite syntax.
Before and After
Before:
select o.id, c.name, sum(oi.qty*oi.price) as total from orders o join customers c on c.id=o.customer_id join order_items oi on oi.order_id=o.id where o.created_at>='2026-01-01' and c.country in ('US','CA') group by o.id, c.name having sum(oi.qty*oi.price)>100 order by total desc limit 50;
After:
SELECT
o.id,
c.name,
SUM(oi.qty * oi.price) AS total
FROM orders o
JOIN customers c
ON c.id = o.customer_id
JOIN order_items oi
ON oi.order_id = o.id
WHERE o.created_at >= '2026-01-01'
AND c.country IN ('US', 'CA')
GROUP BY o.id, c.name
HAVING SUM(oi.qty * oi.price) > 100
ORDER BY total DESC
LIMIT 50;
Same query, same execution plan — but now a reviewer can spot the missing index candidate or the wrong join condition in seconds.
Why Formatted SQL Matters
- Code review — diffs on formatted SQL show exactly which clause changed, instead of a wall-of-text rewrite.
- Debugging — logical errors (a JOIN condition in the wrong place, an AND that should be OR) hide easily in one-liners and jump out in structured form.
- Onboarding and documentation — readable queries in wikis and runbooks save the next engineer hours.
- ORM output analysis — paste the query your ORM generated to understand what it's actually asking the database to do.
SQL Style Conventions Worth Adopting
Uppercase keywords, lowercase snake_case identifiers, leading commas or aligned trailing commas (pick one), explicit JOIN ... ON instead of comma joins, one condition per line in WHERE with AND/OR leading each line, and meaningful table aliases (o for orders, not t1). None of these affect execution — all of them affect how fast the next person understands the query.
Free and Private
Your SQL often contains schema names, business logic, and sometimes literal customer data. This formatter processes everything locally — no server round-trip, no logging, no account. Format an unlimited number of queries of any length.