How to use it
- Paste your SQL query.
- Choose Format or Minify (one line).
- Pick the dialect, keyword case and indentation.
- Copy the result.
What the formatter does
The formatter puts each major clause on its own line, SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, indents the column list and conditions, and applies consistent keyword case. For 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;
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.active = 1
GROUP BY
u.id,
u.name
ORDER BY
orders DESC
LIMIT
10;
Multiple statements are separated by a blank line. Formatting is done by the open-source sql-formatter library (MIT license), running entirely in your browser.
Supported dialects
| Dialect | Notes |
|---|---|
| Standard SQL | Good default for most queries |
| MySQL, MariaDB | Backtick identifiers, LIMIT, MySQL functions |
| PostgreSQL | :: casts, RETURNING, dollar-quoted strings |
| SQL Server (T-SQL) | TOP, square-bracket identifiers, GO |
| Oracle PL/SQL | PL/SQL blocks, CONNECT BY |
| SQLite | SQLite syntax |
| BigQuery | Backtick table paths, STRUCT, ARRAY |
| Snowflake | Snowflake-specific syntax |
Picking the right dialect matters for vendor-specific syntax. If formatting fails with an error, check the dialect first, then look for an unclosed parenthesis or quote.
Options
- Keywords: UPPERCASE (
SELECT,FROM), lowercase, or as typed. Uppercase keywords are the most common convention because they separate SQL syntax from table and column names at a glance. - Indent: 2 or 4 spaces.
- Minify (one line): removes comments and collapses whitespace, leaving strings and quoted identifiers intact. Useful for putting a query into a log message, a JSON field, a one-line config value or a command-line call.
SQL style tips
Formatting handles layout, but a few writing habits make queries easier to maintain:
- Name your columns instead of
SELECT *, so the query does not silently change when the table does. - Use short, meaningful aliases such as
uforusersandofororders, and always qualify columns in joins (u.id, notid). - Prefer explicit joins (
JOIN … ON …) over listing tables with commas and joining inWHERE. - Comment the why, not the what:
-- exclude test accountsexplains a condition better than repeating it. - One statement per purpose. Very long queries are often clearer as common table expressions (
WITH … AS (…)), which the formatter lays out as separate blocks.
Why format SQL
- Reading and debugging: a 40-line query is far easier to follow when each join and condition sits on its own line. Logical errors, like a condition in the wrong
ONclause or a missingGROUP BYcolumn, become visible. - Code review: consistent formatting keeps diffs small and focused on actual changes.
- Documentation: formatted queries in tickets, wikis and runbooks are easier for teammates to reuse.
- Queries from tools: ORMs, BI tools and query logs often produce long single-line SQL. Formatting it is the first step to understanding a slow query.
Privacy
SQL queries can reveal table structures, customer IDs or business logic. This formatter runs completely in your browser: the query is never sent to a server, stored or logged. It is safe to format queries from production systems.
The formatter does not connect to a database or run your query, and it does not check that tables and columns exist. It only changes whitespace and keyword case, so the meaning of the query stays the same.
Frequently asked questions
How do I format an SQL query?
Paste it, choose your dialect and keyword case, and copy the formatted result.
Which SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery and Snowflake.
Why do I get an error?
Usually the dialect does not match the syntax, or a parenthesis or quote is not closed. Try another dialect or check the brackets.
Can I put a query on one line?
Yes. Choose Minify (one line) to remove comments and line breaks.
Is my query uploaded or executed?
Neither. It is formatted in your browser and never run.
Last updated: November 12, 2026