RevealTheme logo

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. 1

    Paste or type your SQL query into the input box.

  2. 2

    The formatted version appears instantly in the read-only panel below — there is no separate Format button.

  3. 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?
For the SQL structure, no — SQL ignores extra whitespace and treats keywords case-insensitively, so reformatting and upper-casing keywords is safe. The exception is content inside string literals, quoted identifiers, and comments: because there is no lexer protecting them, a keyword or comma sitting inside a quoted string can get rewritten. For example WHERE name = 'select one' may have the inner 'select' broken onto a new line. Always sanity-check the output before running it.
Does it support my SQL dialect?
There is no dialect awareness. It pattern-matches against a fixed list of common ANSI-style keywords, so dialect-specific syntax (Postgres, MySQL, T-SQL, BigQuery extensions) is simply left inline rather than formatted. The output still runs on your database — it just won't be specially indented.
Why isn't my subquery indented?
The formatter has no nesting model. Every recognized keyword is pushed to column zero, so a subquery's SELECT lines up with the outer SELECT instead of being indented one level deeper. For nested or deeply structured queries, a parser-based formatter will give better results.
Why did it split my function arguments onto separate lines?
The comma rule applies everywhere, with no understanding of context. Any comma — inside COALESCE(a, b), inside a VALUES tuple, or between SELECT columns — gets a newline and two-space indent after it. That is expected behavior, not a bug.
Does it check my SQL for errors?
No. It does no validation, linting, or syntax checking. Invalid SQL will be reformatted just the same. Run the output through your database client or a linter if you need correctness checks.
Is my query uploaded anywhere?
No. The formatter runs entirely in your browser with JavaScript — your SQL is never sent to a server, logged, or stored. You can use it on sensitive queries offline once the page has loaded.

Related tools