SQL Formatter
Format and beautify single-line or minified SQL — line breaks before major keywords and a two-space indent after every comma.
How to use this tool
- 1
Paste or type your SQL query into the input box.
- 2
The formatted version appears instantly in the read-only panel below — there is no separate Format button.
- 3
Select the output text and copy it manually into your editor or query tool.
How does this SQL formatter actually work?
This is a lightweight, regex-based formatter rather than a full SQL parser. It first collapses every run of whitespace in your query down to single spaces, then inserts a line break before each keyword in a fixed list of about 25 common ones — SELECT, FROM, WHERE, the JOIN variants, GROUP BY, ORDER BY, HAVING, LIMIT, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, CREATE/ALTER/DROP TABLE, UNION, AND, and OR. Those keywords are also upper-cased. Finally, it adds a newline plus two spaces after every comma. Because it works by pattern matching and not by parsing the grammar, it has no awareness of nesting: every keyword line starts at column zero, so subqueries are not indented more deeply than the outer query. Keywords outside its list — DISTINCT, AS, WITH and CTEs, CASE/WHEN, BETWEEN, IN, LIKE, CROSS JOIN, FULL JOIN — are left inline. The comma rule is also context-blind, so it splits function arguments like COALESCE(a, b) and multi-row VALUES tuples the same way it splits a SELECT column list. It is meant for a quick readability pass on flat queries, not for pretty-printing complex statements to a style guide.
Common use cases
Untangling a one-line SQL query copied out of an application log or ORM debug output so you can read it.
Quickly making a SELECT with a long column list scannable before reviewing it in a pull request.
Normalizing keyword casing to uppercase across an ad-hoc query you wrote in lowercase.
Pasting a minified query from a config file or migration into a readable shape for documentation.
Teaching or explaining a query's clause structure by breaking SELECT, FROM, WHERE, and JOIN onto their own lines.
Doing a fast cleanup before a query is too short to justify opening a full IDE formatter.
Frequently asked questions
Will this change what my query does?▼
Does it support my SQL dialect?▼
Why isn't my subquery indented?▼
Why did it split my function arguments onto separate lines?▼
Does it check my SQL for errors?▼
Is my query uploaded anywhere?▼
Related tools
JWT Decoder
Decode JSON Web Tokens (JWT) instantly — inspect the header, payload, and signature claims. Runs entirely in your browser; tokens never leave your device. Safe for production secrets.
JSON Formatter & Validator
Format, validate, and minify JSON instantly. Catches syntax errors with line numbers, pretty-prints with adjustable indent, supports large payloads. Runs in your browser — no upload.
XML Formatter & Beautifier
Format and beautify XML documents — proper indentation, line breaks, namespace handling. Useful for SOAP responses, sitemaps, RSS feeds, and Android resource files.
Base64 Encoder & Decoder
Encode and decode Base64 strings.
URL Encoder & Decoder
Encode/decode URL-safe strings.
HTML Entity Encoder & Decoder
Convert special characters to/from HTML entities.