Format SQL
A readable shape for a query you inherited.
Everything is processed in this tab. Nothing you paste is sent anywhere.
Every tool runs entirely in your browser. Your files are never uploaded to a server.
Formatting SQL puts each major clause on its own line and cases keywords consistently. It changes only the layout — the query executes identically, since SQL ignores whitespace outside string literals.
How to use SQL Formatter
- Paste your query. However it arrived — one line is the usual case.
- Choose keyword casing. Uppercase keywords are the long-standing convention.
- Copy the formatted query. Behaviour is unchanged; only whitespace and casing move.
About formatting SQL
SQL treats whitespace as insignificant outside string literals, which means formatting is purely a readability exercise and carries no risk to behaviour. That is worth stating because a query is often the artefact people are most reluctant to touch — it works, it is going to production, and reformatting feels like a change. It is not one; the parser sees the same token sequence either way. The conventional layout puts each major clause on its own line, because those clauses are what the reader is looking for. Finding the FROM in a two-hundred-character single line means reading the whole thing; finding it at the start of a line takes no effort at all. Joins get the same treatment, with their ON conditions indented beneath, which makes the shape of a multi-table query visible before any of it is read closely. Keyword casing is convention rather than requirement — SQL keywords are case-insensitive — and uppercase is the long-standing choice because it visually separates the language from the identifiers around it. The one place a formatter can genuinely break something is string literals. A keyword inside a quoted value is data, and uppercasing it or collapsing whitespace within it changes what the query does. Extracting quoted sections before any other transformation and restoring them afterwards is the only reliable way to avoid it, and it is the difference between a formatter that is safe on real queries and one that works on the examples in its own documentation.
Frequently asked questions
Does formatting change how the query runs?
Why uppercase keywords?
Will it handle a keyword inside a string?
Does this validate my SQL?
Is my query uploaded?
Last updated