SQL Formatter & Beautifier
Format and beautify SQL queries instantly. Supports MySQL, PostgreSQL, SQLite, T-SQL, PL/SQL and more.
Why Format SQL?
- Improves readability for code reviews
- Easier to debug complex queries
- Consistent style across a team
- Helps spot syntax errors quickly
- Required for documentation and wikis
Supported Dialects
- Standard SQL
- MySQL
- PostgreSQL
- SQLite
- T-SQL (SQL Server)
- PL/SQL (Oracle)
- MariaDB
- IBM DB2
- BigQuery
- Apache Hive
- Apache Spark
- Trino
Formatting Options
- 2, 3, 4 space or tab indentation
- Uppercase or lowercase keywords
- Blank lines between multiple queries
- Clause-per-line layout (SELECT, FROM, WHERE…)
- Download as
.sqlfile
About the SQL Formatter & Beautifier
The SQL Formatter takes messy, compressed, or hand-written SQL queries and reformats them into clean, consistently indented, human-readable code. It supports 12 SQL dialects including MySQL, PostgreSQL, SQLite, T-SQL (SQL Server), PL/SQL (Oracle), BigQuery, and Apache Spark — covering virtually every database platform in common use.
All formatting runs entirely in your browser using the open-source sql-formatter library.
No SQL is ever sent to a server, making this tool safe for production queries, credentials, and sensitive schemas.
How to Format SQL Online
- Paste your SQL query into the Input SQL box, or click one of the example buttons (Simple SELECT, Subquery, INSERT, CTE).
- Choose your Dialect from the dropdown — select the database engine your query targets for dialect-aware formatting.
- Select an Indent style: 2 spaces, 3 spaces, 4 spaces, or tab.
- Toggle Uppercase Keywords to control whether SQL keywords like SELECT, FROM, and WHERE are uppercased or lowercased.
- Click Format SQL — the formatted result appears instantly in the right panel.
- Click Copy to copy the output, or Download to save it as a
.sqlfile.
Common Use Cases for SQL Formatting
- Code reviews — Format queries before submitting a pull request so reviewers can focus on logic, not style.
- Debugging complex queries — Break apart nested subqueries and CTEs into readable, clause-per-line layouts to spot errors faster.
- Documentation and wikis — Paste clean, indented SQL into Confluence pages, READMEs, and runbooks.
- ORM output inspection — Format the raw SQL generated by ORMs (Django, SQLAlchemy, Hibernate) to understand what queries are being executed.
- Database migration scripts — Beautify long DDL statements (CREATE TABLE, ALTER TABLE) before committing to version control.
- Learning SQL — Paste unformatted example queries and see how clauses map to clean structure.
- Log analysis — Reformat SQL queries extracted from slow query logs or monitoring tools for easier reading.
Frequently Asked Questions
Which SQL dialects are supported?
The formatter supports Standard SQL, MySQL, PostgreSQL, SQLite, T-SQL (SQL Server), PL/SQL (Oracle), MariaDB, IBM DB2, BigQuery, Apache Hive, Apache Spark, and Trino. Select the appropriate dialect to get the most accurate formatting for your database platform.
Does formatting change what my SQL does?
No. SQL formatting only affects whitespace, indentation, and keyword casing — it does not modify the logic, structure, or execution of your query. The formatted output is semantically identical to the input.
Is my SQL sent to a server?
No. All formatting is performed client-side in your browser. Your queries, table names, and data values never leave your device. This makes the tool safe to use with production SQL containing sensitive information.
Why should I uppercase SQL keywords?
Uppercased keywords (SELECT, FROM, WHERE, JOIN) visually distinguish SQL syntax from identifiers and values, making queries easier to scan. Most SQL style guides recommend uppercase keywords, though lowercase is also valid and some teams prefer it.
Can I format multiple SQL statements at once?
Yes. Paste multiple semicolon-terminated statements and the formatter will process all of them, adding blank lines between queries for clarity.
What indentation style should I use?
2 spaces is common in web-focused projects and matches many linter defaults. 4 spaces is preferred in enterprise and data engineering environments. Tab indentation lets each developer set their own display width in their editor.
What is a CTE and how does the formatter handle it?
A Common Table Expression (CTE) is a named subquery defined with the WITH clause. The formatter correctly indents each CTE body and the final SELECT separately, making complex multi-CTE queries much easier to follow.