Free SQL Formatter & Beautifier
Turn a cramped one-line SQL query into clean, consistently indented SQL. This formatter breaks queries at the major clauses (SELECT, FROM, WHERE, JOIN, GROUP BY, and more) and aligns them for easy reading.
Query work continues with the SQL to CSV Converter, and the tables it returns can be reshaped with the CSV to JSON Converter. To translate the same statement between dialects, the SQL to CSV Converter is the tool.
How to use the SQL Formatter
- 1 Paste your SQL statement or script.
- 2 Choose the keyword casing — uppercase is the convention.
- 3 Format. Clauses move onto their own lines and nested subqueries gain indentation.
- 4 Check the output for any statement the parser did not recognise.
Formatting as a review tool
The clearest use of a SQL formatter is on a query someone else wrote, or one you wrote months ago. Restoring indentation reveals the shape of the query — which clauses are inside which subquery, and where the join conditions actually sit — in a way that scanning raw text does not.
It is also a good first step when a query is slow. Before reaching for an execution plan, formatting it makes the obvious problems visible: a join written as a cross join with the condition in the `WHERE` clause, a subquery re-executed per row, or a `SELECT *` pulling columns nobody uses.
- One clause per line is the convention.
- Subqueries are indented by nesting depth.
- Window functions and CTEs are the constructs most often mangled.
- Whitespace costs nothing at execution time.
What the formatter handles
The formatter understands the standard SQL structure, splits comma-separated column lists, indents JOIN conditions and sub-clauses, and normalizes a broad set of common keywords (SELECT, INSERT, UPDATE, DELETE, CREATE, JOIN, ON, AND, OR, and many more). String literals and comments are preserved as-is.
Frequently asked questions
Why does formatting SQL matter when the database does not care?
Because people care. A long query written on one line is effectively unreadable, and unreadable queries are where performance problems hide — a missing join condition or a correlated subquery inside a loop is invisible in a wall of text and obvious once the structure is laid out.
Which modern features does the formatter need to handle?
Window functions with their `OVER` clauses, common table expressions declared with `WITH`, lateral joins, and the various dialect-specific constructs for JSON and arrays. These are the places where a naive formatter mangles the statement, so check the output on anything using them.
Should I format my queries in application code?
Prefer keeping the query readable in the source and letting the database parse it. Whitespace has no cost at execution time, and a readable query in version control means the next diff shows the actual change rather than a single rewritten line.
Related Developer Tools
You might also need
Tools from other categories that people pair with the SQL Formatter: