SQL Formatter
Beautify messy SQL.
SQL Formatter at a glance
SQL Formatter is a free online developer tool you can use right now to beautify messy SQL โ no account, no install and no usage limit. It runs entirely inside your browser, so whatever you enter stays on your own device.
- Price
- Free โ no trial, no paid tier, no watermark
- Sign-up
- Not required
- Where it runs
- In your browser โ nothing is uploaded to a server
- Works on
- Chrome, Safari, Firefox and Edge โ desktop, tablet and phone
- Category
- Developer Tools
About SQL Formatter
Paste a query that arrived as one long line โ from a log, an ORM's debug output or a colleague's message โ and get it back with each clause on its own line and joins and conditions indented sensibly.
This matters most for the queries that are hard to read precisely when you most need to read them. A five-table join with several conditions and a subquery is nearly impossible to reason about unformatted, and that is usually the query you are looking at because it is slow or returning the wrong rows.
Formatting frequently exposes a specific class of bug: a join condition that ended up in the WHERE clause instead of the ON clause. Both often return the same rows for inner joins, so the mistake is invisible โ until someone changes it to a LEFT JOIN, at which point the WHERE condition silently filters out exactly the unmatched rows the left join was added to keep. Laid out clearly, the misplaced condition is easy to see.
Formatting is cosmetic and changes nothing about execution: SQL ignores whitespace, so the query plan is identical before and after. If a query is slow, read the execution plan rather than reformatting it โ though a formatted query is considerably easier to read the plan against.
How to use SQL Formatter
- Paste your SQL query into the box.
- Clauses are placed on their own lines with consistent indentation.
- Copy the formatted query back into your editor or documentation.
Frequently asked questions
Does formatting change how the query runs?
No. SQL ignores whitespace, so the parsed statement and the execution plan are identical. Formatting only affects readability.
Will it work with my database's dialect?
Standard SELECT, INSERT, UPDATE, DELETE and JOIN syntax formats correctly across MySQL, PostgreSQL, SQL Server, SQLite and Oracle. Vendor-specific extensions and procedural blocks may format less cleanly, since they are not part of standard SQL.
Should a join condition go in ON or WHERE?
In ON. For inner joins both usually return identical rows, which hides the mistake โ but with a LEFT JOIN a condition in WHERE filters out the unmatched rows the left join was meant to preserve, quietly converting it into an inner join.
Is my query sent to a server?
No. Formatting happens entirely in your browser, so queries containing table names, schema details or embedded values stay on your device.