DevOps

SQL Formatter

Format and indent SQL queries for readability. Handles joins, subqueries and CTEs, supports common dialects, and runs entirely in your browser.

SQL Formatter

Format detailed SQL queries for better readability.

Want this automated for your stack?

We build CI/CD, Kubernetes & IaC pipelines that scale.

Talk to an engineer

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.

Frequently Asked Questions

Privacy & Security

Formatted locally.

Data: None
Client-side-Side
Active
v1.0

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.