SQL Formatter & Beautifier
Format SQL online with dialect-aware indentation: MySQL, PostgreSQL, SQL Server, Oracle, BigQuery and more. Set keyword case and width. Runs in your browser.
How to use SQL Formatter
- 1Paste your SQL or open a .sql file, then pick the dialect that matches your database.
- 2Set keyword case, indent, blank lines between queries and expression width.
- 3Copy or download the formatted SQL. Switch Mode to Minify or Validate to do those jobs on the same text.
What makes it better
- 20 dialects including MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, Oracle PL/SQL, BigQuery, Redshift, Snowflake and Spark
- Keywords in UPPER, lower or original case; table, column and function names are never recased
- Indent with 2 spaces, 4 spaces or tabs, with the logical operator (AND/OR) at the start or end of the line
- Same page also minifies and validates: Mode switches without clearing your SQL
- Parse errors point to the line and column instead of failing silently
About SQL Formatter
SQL Formatter rewrites a one-line or messy query into indented clauses, one column or condition per line, using the sql-formatter library for the dialect you pick. You choose keyword case, 2 or 4 spaces or tabs, blank lines between statements and how wide an expression may get before it wraps. The same page can also minify the query or run a quick bracket-and-quote check, and nothing you paste leaves the browser.
Common uses
- Make a one-line query copied from an ORM log or a slow-query log readable before you tune it.
- Give a team one layout for SQL pasted into pull requests, migrations and documentation.
- Tidy a long report query with several joins before sending it to an analyst.
- Check that a query still balances its parentheses and quotes after you edited it by hand.
Example
Input
select o.id, c.name, sum(oi.qty * oi.price) as total from orders o join customers c on c.id = o.customer_id left join order_items oi on oi.order_id = o.id where o.status = 'paid' and o.created_at >= '2026-01-01' group by o.id, c.name having sum(oi.qty * oi.price) > 100 order by total desc limit 10;
Result
SELECT o.id, c.name, sum(oi.qty * oi.price) AS total FROM orders o JOIN customers c ON c.id = o.customer_id LEFT JOIN order_items oi ON oi.order_id = o.id WHERE o.status = 'paid' AND o.created_at >= '2026-01-01' GROUP BY o.id, c.name HAVING sum(oi.qty * oi.price) > 100 ORDER BY total DESC LIMIT 10;
Good to know
- Formatting never runs your SQL and does not know your schema. It re-lays out the tokens, so a query that is logically wrong stays logically wrong.
- The formatter has to understand the dialect's syntax. If a valid statement is rejected, try the dialect that matches your database; the generic Standard SQL option is the strictest about vendor extensions.
- Procedural blocks (stored procedures, triggers, PL/SQL packages) are laid out less predictably than plain queries, and comments are kept in place rather than reflowed.
SQL Formatter FAQ
How do I format a SQL query online?
Paste the query, choose your database from the Dialect menu and read the result on the right. Each clause (SELECT, FROM, WHERE, GROUP BY) starts a new line and columns and conditions get one line each. Copy it or download it as a .sql file.
Which SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Amazon Redshift, Snowflake, Spark SQL, Hive, Trino, DuckDB, IBM Db2, TiDB, SingleStoreDB, ClickHouse and Couchbase N1QL. Pick the one that matches the database the query will run on.
Will formatting change what my query does?
It should not: only whitespace, line breaks and the case of reserved keywords change. Identifiers, function names and string contents are left exactly as written. It is still worth running the result once before you rely on it in production.
Can I keep keywords in lower case?
Yes. Keyword case can be upper, lower or preserve (leave it as typed). The setting only touches reserved words such as select and join, never table or column names.
Why does it say a parse error on my valid SQL?
Each dialect has its own grammar, and vendor-specific syntax outside it is rejected. Choose the matching dialect, check for an unclosed quote or bracket in Validate mode, and note that the error shows the line and column it stopped at.