What is SQL?
SQL (Structured Query Language) is the standard language for working with relational databases. It’s used to query, insert, update, and delete data in databases like PostgreSQL, MySQL, SQLite, and SQL Server. SQL queries are written as text statements, and their readability depends heavily on how they’re formatted.
When SQL is generated programmatically, copied from logs, or pasted from external sources, it often arrives as a dense single line — keywords run together, indentation is absent, and subqueries are hard to follow. Reformatting it properly makes queries far easier to understand, debug, and share.
What Does This Tool Do?
This tool takes raw or minified SQL and formats it with consistent indentation, keyword capitalization, and line breaks. It supports standard SQL as well as common dialects. The result is clean, readable SQL that’s easier to review and modify.
How to Use This Tool
- Paste your SQL query into the input area.
- The formatted version appears immediately.
- Adjust indentation size if needed.
- Copy the result with the copy button.
- For long queries, switch the View control to Output to read the formatted SQL at full width.
Common Use Cases
- Code review: Make a complex query readable before sharing it in a pull request or ticket.
- Debugging: Understand a query that was auto-generated by an ORM or query builder.
- Documentation: Format queries clearly before including them in documentation or reports.
- Learning: See well-formatted SQL to learn proper style and structure.
Before and After
A query as it typically arrives from a log or ORM:
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.created_at>'2026-01-01' and u.status='active' group by u.id,u.name having count(o.id)>5 order by orders desc limit 20;
The same query formatted:
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.created_at > '2026-01-01'
AND u.status = 'active'
GROUP BY
u.id,
u.name
HAVING
COUNT(o.id) > 5
ORDER BY
orders DESC
LIMIT
20;
Same execution plan, radically different readability — the join condition, the two filters, and the aggregation threshold are now visible at a glance.
SQL Style Conventions Worth Adopting
- Uppercase keywords (
SELECT,WHERE,JOIN) — visually separates structure from your identifiers. - One column per line in long select lists — makes diffs reviewable when a column is added or removed.
- Leading
AND/ORon condition lines — easy to comment out a single condition while debugging. - Explicit
JOIN … ONinstead of comma joins — the join condition can’t be accidentally forgotten (the classic accidental cartesian product). - Alias with
AS— optional in most dialects but makes intent explicit.
Consistency matters more than any specific choice: a team that formats queries the same way reviews them faster.
Frequently Asked Questions
Which SQL dialects are supported?
The formatter supports standard SQL and handles common patterns from PostgreSQL, MySQL, and SQL Server. Very dialect-specific syntax may not be perfectly formatted, but most standard queries work correctly.
Does formatting change how a query runs?
No. Formatting only affects whitespace and capitalization — it has no effect on query execution or results.
Is my data private?
Yes. All formatting happens in your browser. Your SQL queries are never sent to any server.
Can I format SQL that contains parameters or placeholders?
Yes — placeholders like ?, $1, :name, or @param pass through the formatter unchanged, so queries copied from application code or prepared statements format cleanly.
Does the formatter validate my SQL?
Only loosely. It parses enough structure to format correctly and will complain about badly broken syntax, but it doesn’t check that tables exist or types match — that’s your database’s job. A query can format beautifully and still fail to run.