What it does
The SQL Formatter lays out queries so they are easy to read and review: each clause on its own line, consistent indentation and keyword case of your choice. It knows the syntax of the major databases, so dialect-specific features are formatted correctly.
Supported dialects: Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark and DB2.
How to use it
- Paste a query into the Query pane or click Load sample.
- Choose your Dialect.
- Pick keyword case (KEYWORDS upper, keywords lower or Keywords as-is) and the indent.
- Click Format, or Minify to put the query on one line. Copy the result.
Example
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.active=1 group by u.id,u.name order by orders desc limit 10
Formatted, with upper-case keywords:
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.active = 1
GROUP BY
u.id,
u.name
ORDER BY
orders DESC
LIMIT
10
Good to know
- Formatting changes only whitespace and keyword case, never the meaning of the query. Function names such as
countkeep the case you typed. - Choosing the right dialect matters for things like
TOP(T-SQL), backtick identifiers (MySQL) or::casts (PostgreSQL). - The formatter does not run queries or check that tables exist.
FAQ
Will formatting break my query? No. It only re-lays out the text. If the input has a syntax error, formatting may stop with a message instead.
Can I format several statements at once? Yes. Separate them with semicolons as usual.