SQL Formatter
Format SQL queries with uppercase keywords and line breaks.
What is SQL Formatter
SQL formatting uppercases keywords and adds line breaks and indentation per clause, making queries easier to read.
🔒 Everything runs in your browser. Nothing is uploaded.
What this tool actually does with your file
- Where it runs
- In your browser, on this page
- Upload
- None — the file never leaves your device
- Offline
- Works with the network disconnected
String literals are protected before anything moves
Every single-quoted literal is swapped for a placeholder, the text is reformatted, and the literals are restored afterwards. Without that step, a keyword inside a string — WHERE note = 'order by date' — would be treated as syntax and split across lines, changing the query's meaning.
The formatter then breaks on major clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOIN) and indents their bodies. It does not parse the statement: it has no grammar, so it will happily format text that no database would execute.
Dialects it will misrepresent
Quoting differs per database: MySQL uses backticks, SQL Server brackets, PostgreSQL and the standard use double quotes for identifiers and single quotes for strings. PostgreSQL's dollar-quoted strings ($$ … $$) and MySQL's /*! */ executable comments are not recognised, so their contents may be reflowed.
That does not corrupt the query as sent to the database — the original text is unchanged apart from whitespace — but it does make the formatted version misleading to read. Verify against the original if the statement contains any of those constructs.
What formatting is for
Readability in review, and making a generated query legible. The output has no performance meaning: a database's planner ignores whitespace entirely, so a beautifully indented query and the same query on one line produce identical plans.
For correctness, formatting proves nothing. Run EXPLAIN on the real database, and use a schema-aware linter if you want to catch missing columns or type mismatches — neither is detectable from the text alone.
How to use it
- 1.Paste your SQL
- 2.Click Format
- 3.Copy the result
How SQL Formatter works under the hood
Formatters parse your input into a structure, then serialise it back with consistent indentation. That is why a formatter can also reveal a syntax error: if it cannot parse, it cannot print.
- 1
Parse into a tree
JSON goes through JSON.parse; YAML, XML, CSS and SQL use their own parsers. The parse either succeeds with a structure or fails at a line and column.
- 2
Serialise with a fixed style
Indentation width, key order and quoting are applied deterministically, so formatting the same input twice gives identical bytes.
- 3
Show the error position
When parsing fails, the message includes the position so the fix is obvious instead of guessed.
Processing pipeline
Formatting and minifying are inverse operations on the same data — no value changes. The formatter re-parses with JSON.parse, so a trailing comma or a // comment makes it fail with the parser's own message: JSON has neither. The highlighted null is a real value, not a missing one — a missing field would simply have no row.
Formatting is not validation
A formatter proves the document is syntactically parseable. It does not prove it is valid against a schema, and it does not check business rules. JSON with a duplicated key parses fine and silently keeps the last value.
What gets normalised
Comments are preserved in CSS and SQL but not in JSON, which has no comment syntax. YAML anchors may be expanded, and quote style may change. Keep the original when exact byte layout matters, such as signed payloads.
Verify it yourself
Formatting is deterministic and local — run it twice and compare.
- 1.Open DevTools on this page and switch to the Network tab
- 2.Keep the filter on Fetch/XHR and run the tool
- 3.Confirm no request carries your file — you should see only page assets and fonts
Frequently asked questions
What is SQL formatting?
It uppercases keywords and breaks clauses into lines for readability.
What about string literals?
Quoted strings are protected and kept intact.
What this kind of conversion cannot keep
Formatters parse the input into a tree and print it back with consistent indentation. If the input is invalid, you get the parser's error position instead of a silently mangled file — malformed JSON stays malformed rather than being «repaired» into something that is no longer yours.
More in Format
On this page
- What is SQL Formatter
- What this tool actually does with your file
- How it actually behaves
- How to use it
- How it works inside
- Frequently asked questions
Excel formula reference
29 functions with syntax, arguments and a table you can retype.
Browse the list →