How to Format SQL Queries So They Are Easy to Read
SQL FormatterBeautify SQL for any database. Free, no sign-up.SQL copied from logs, ORMs 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 is selected, joined and filtered.
Format a query
- Open the SQL Formatter and paste your query (or several, separated by semicolons).
- Choose your dialect: PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark or standard SQL.
- Choose keyword case (UPPER, lower or as written) and indentation (2 spaces, 4 spaces or tabs).
- Copy the result.
The query is formatted in your browser. It is not sent to a server or run against any database, so queries with table names or real values stay private.
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 PostgreSQL, 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 has to understand:
- Quoting identifiers:
"name"in PostgreSQL,`name`in MySQL,[name]in SQL Server. - Placeholders:
$1in PostgreSQL,?in MySQL and SQLite,@paramin SQL Server. - Special syntax:
QUALIFYin Snowflake and BigQuery,TOPin SQL Server.
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 the diff.
AND/ORat the start of the line, so conditions line up and are easy to comment out.- Uppercase keywords or lowercase keywords, but the same everywhere in a project.
- Explicit
JOIN … ONinstead of comma joins. - Aliases that mean something (
orders ois fine;t1,t2is not).
To see what really changed between two versions of a long query, format both the same way and compare them with the Diff Checker. Formatting differences then disappear and only real changes remain.
Limitations
The formatter changes layout only. It does not check that tables or columns exist, run the query, or tell you whether it is fast. Use EXPLAIN in your database for that.