Make SQL readable
Queries copied from logs, generated by an ORM or written in a hurry often end up as a single long line that's hard to read and even harder to debug. This SQL formatter breaks your query into clear clauses — SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY — puts each column and condition on its own line and indents subqueries and CASE expressions consistently. The result is easier to review, to compare in version control and to share with colleagues.
Features
- 12 SQL dialects, from standard SQL to MySQL, PostgreSQL, SQL Server, Oracle, BigQuery and Snowflake.
- Keyword case: UPPER, lower or exactly as written; applies to keywords, data types and functions.
- Indentation with 2 spaces, 4 spaces or tabs.
- Multiple statements separated by semicolons.
- Comments preserved — both
--line comments and/* */block comments. - Copy or download the result as a
.sqlfile. - Private: the formatter runs locally in your browser.
Before and after
A query like this:
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.status = 'active' group by u.id, u.name order by orders desc;
becomes:
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.status = 'active'
GROUP BY
u.id,
u.name
ORDER BY
orders DESC;
SQL style tips
- One clause per line. Starting each major clause on a new line makes the structure of a query visible at a glance.
- Use meaningful aliases. Short aliases such as
uandoare fine for small queries, but descriptive ones help in long reports. - Qualify column names in joins (
orders.user_idrather thanuser_id) to avoid ambiguity. - Keep formatting consistent across a project so diffs show real changes, not whitespace.
Related tools
Working with query results? Convert exported data with CSV to JSON, pretty-print API responses with the JSON Formatter, or compare two versions of a query with the Diff Checker.