Guide
Formatting SQL queries so they're readable and reviewable
SQL copied from logs, ORMs, slow-query reports or monitoring tools usually arrives as one long line. Formatting it puts each clause on its own line, so you can see at a glance what’s selected, joined, filtered and grouped. This formatter understands eleven SQL dialects and runs in your browser.
Formatting a query
- Paste a query, or several separated by semicolons. A sample query is loaded to start with.
- Choose your dialect: Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift or Spark SQL.
- Choose keyword case (UPPER, lower or as typed) and indentation (2 spaces, 4 spaces or tabs).
- Copy the result or download it as query.sql.
Your choices are remembered, so the next query is formatted the same way.
Before and after
select id, name, email from customers where country = 'DE' and created_at >= '2026-01-01' order by created_at desc limit 50;
With uppercase keywords and 2-space indentation:
SELECT
id,
name,
email
FROM
customers
WHERE
country = 'DE'
AND created_at >= '2026-01-01'
ORDER BY
created_at DESC
LIMIT
50;
Why the dialect matters
Databases disagree on details the formatter needs to understand:
| Detail | PostgreSQL | MySQL | SQL Server |
|---|---|---|---|
| Quoting identifiers | "name" |
`name` |
[name] |
| Placeholders | $1 |
? |
@param |
| Limiting rows | LIMIT 10 |
LIMIT 10 |
TOP 10 |
Snowflake and BigQuery add QUALIFY, Oracle has PL/SQL blocks, and Spark SQL has its own functions. If formatting fails, the dialect is the first thing to check.
Conventions that help in code review
- One selected column per line, so adding a column is a one-line change in a diff.
- AND and OR at the start of the line, so conditions line up and are easy to comment out.
- Consistent keyword case across the project, upper or lower.
- Explicit JOIN … ON instead of comma joins with conditions in WHERE.
- Meaningful aliases:
orders ois fine;t1,t2is not. - CTEs (WITH … AS) for long queries, so each step has a name.
Comparing two versions
To see what really changed between two versions of a long query, format both with the same settings and compare them with the Diff Checker. Formatting differences disappear and only real changes remain, ideal for reviewing a query change in a pull request or comparing what an ORM generated before and after an update.
What formatting can’t do
The formatter changes layout only. It doesn’t check that tables or columns exist, doesn’t run the query, and can’t tell you whether it’s fast. For performance, use EXPLAIN (or EXPLAIN ANALYZE) in your database, and look for missing indexes, unexpected full scans and joins that multiply rows.
Privacy
Queries can reveal table structures and real values. Everything is formatted in your browser and nothing is sent to a server or any database.
Who formats SQL
- Developers read queries generated by ORMs and logged by databases.
- Data analysts tidy long reporting queries before sharing them.
- Database administrators review slow queries from monitoring tools.
- Students learn SQL structure and style.
A complete example: reviewing a slow query
- Copy the slow query from the database’s slow-query log.
- Paste it and choose your database’s dialect.
- Read the formatted query: which tables are joined, and what filters are applied.
- Run EXPLAIN on it in your database and check whether the filtered columns have indexes.
Tips
- Format both versions before comparing changes in the Diff Checker.
- Agree on keyword case and indentation as a team.
Related tools
- Diff Checker to compare two formatted queries.
- JSON Formatter for API responses and JSON columns.
- CSV to JSON for turning query exports into JSON.
Checked against the current version of the SQL Formatter on .

