How to Format SQL Online — Free SQL Beautifier (Postgres, MySQL, SQLite)
Format and beautify SQL queries online — proper indentation, capitalized keywords, aligned clauses. Supports Postgres, MySQL, SQLite, SQL Server syntax. Free, no signup.
Why formatting matters for SQL specifically
A 20-line SQL query is often harder to understand than a 200-line function in most languages. Joins across three tables, filters in WHERE, grouping, window functions, subqueries — when these are jammed on one line with inconsistent capitalization, even the author needs a minute to re-parse. Consistent formatting turns that into "read once, understand."
What the SQL formatter does
- Uppercases reserved keywords —
SELECT,FROM,WHERE,JOIN,ON - Aligns clauses vertically — one keyword per line, easy to scan
- Indents nested subqueries consistently
- Breaks long SELECT lists one column per line when they exceed a threshold
- Preserves your exact string literals and comments — no accidental semantic changes
Example transformation
-- Before
select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.created_at > '2025-01-01' group by u.id, u.email having count(o.id) > 5 order by orders desc;
-- After
SELECT
u.id,
u.email,
COUNT(o.id) AS orders
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.created_at > '2025-01-01'
GROUP BY u.id, u.email
HAVING COUNT(o.id) > 5
ORDER BY orders DESC;
Dialect support
| Dialect | Notes |
|---|---|
| Postgres | Default; supports CTEs, window functions, arrays, JSONB operators |
| MySQL | Backtick identifiers handled; USE statements recognized |
| SQLite | Concise syntax; bare-bones but complete |
| SQL Server (T-SQL) | Square-bracket identifiers; TOP instead of LIMIT |
| MariaDB | MySQL-compatible; extra analytical functions |
Pair with explain plans
Formatting doesn't make a query fast — it makes it readable. For actual performance work, run EXPLAIN ANALYZE (Postgres) or EXPLAIN (MySQL) and inspect the plan. A formatted query is easier to pattern-match against indexing advice.
Related tools
For JSONB and JSON columns in Postgres, pretty-print the JSON with JSON formatter. For comparing two query versions side-by-side (e.g., before and after refactoring), diff checker highlights what changed.
Featured Tools
Try these free tools directly in your browser — no sign-up required.
SQL Formatter
Format and beautify SQL queries instantly online. Clean up minified or messy SQL with proper indentation, keyword capitalisation, and clause alignment.
JSON Formatter
Format, beautify, and validate JSON instantly. Paste raw JSON and get a clean, indented, human-readable output with syntax error detection.
Code Beautifier
Beautify and format code in JavaScript, TypeScript, HTML, CSS, JSON, and more. Auto-indent and clean up messy code with configurable style options.
Diff Checker
Compare two texts or code files side by side and highlight differences. Find added, removed, and changed lines instantly with colour-coded diff output.