SQL Query Formatter
Format and indent SQL queries for readability. Handles joins, subqueries and CTEs, supports common dialects, and runs entirely in your browser.
Last reviewed by the Radiatus Cloud team
SQL Formatter
Format detailed SQL queries for better readability.
Need this built for your product?
We design, build & host secure software & APIs.
Why formatting SQL matters more than formatting most code
SQL is written as one long expression, so a query that grows past a dozen lines becomes genuinely hard to reason about. Unlike a program, there are no functions to break it into. Formatting is the only structural tool available: consistent indentation is what makes the join order, the filter conditions and the grouping visible at a glance.
The conventions that help
Leading commas in a select list make it obvious which column a line belongs to and let you comment out a line without breaking the syntax of the line above. Putting each JOIN on its own line with its ON clause indented beneath shows the join graph clearly. Aligning AND conditions under the WHERE keyword makes it visually obvious when an OR has been added without parentheses, which is one of the more damaging silent SQL bugs.
Common table expressions
A CTE chain reads top to bottom, which is why they are usually clearer than deeply nested subqueries even when the query plan is identical. Formatting each WITH block as a separate indented unit preserves that readability. Where a query has three or more levels of nested subquery, rewriting it as CTEs almost always helps the next person to read it.
Dialects differ
SQL is standardised in principle and divergent in practice. PostgreSQL, MySQL, SQL Server, Oracle and SQLite each have their own quoting rules, string concatenation operators, limit and offset syntax, and reserved words. Identifier quoting is the most visible difference: double quotes in PostgreSQL, backticks in MySQL, square brackets in SQL Server. A formatter that assumes the wrong dialect can mangle quoted identifiers, so set the dialect before formatting.
Formatting is not optimisation
Reformatting changes only whitespace and capitalisation. It does not alter the query plan, and a beautifully formatted query can still be catastrophically slow. If performance is the problem, read the execution plan: look for sequential scans on large tables, missing indexes on join columns, and functions applied to indexed columns in the WHERE clause, which prevents index use.
Nothing leaves your browser
Queries frequently contain table names, column names and literal values that reveal schema and business logic. Formatting runs locally so none of it is transmitted.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
- HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
Frequently Asked Questions
Does formatting change how my query runs?
No. Formatting alters only whitespace, line breaks and keyword capitalisation. The parsed query and its execution plan are identical. If the query is slow, formatting will not help; read the execution plan instead.
Which SQL dialect should I choose?
The one your database actually uses. Identifier quoting differs the most: double quotes in PostgreSQL, backticks in MySQL, square brackets in SQL Server. A formatter set to the wrong dialect can mangle quoted identifiers.
Should keywords be uppercase?
It is a widespread convention because it separates SQL keywords from your identifiers visually, which helps a lot in long queries. It has no functional effect. Consistency within a codebase matters more than the specific choice.
Are CTEs better than subqueries?
For readability, usually yes: a WITH chain reads top to bottom instead of inside out. For performance it depends on the database, since some materialise CTEs and others inline them. Modern PostgreSQL inlines them unless told otherwise.
Is my query sent to a server?
No. Formatting runs in your browser. Queries expose schema and business logic through table and column names, so keeping them local matters.
Privacy & Security
Formatting done locally.
About This Tool
This tool runs entirely in your browser. No data is sent to any server, ensuring complete privacy. Simply use the interface above to get started — no registration or login required.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.