SQL Formatter

Paste a query written as one long line and get it back readable: each clause on its own line, joins and their conditions indented under the table they attach to, subqueries nested visibly, and keywords cased consistently. The query is tokenised before any rule is applied, which matters more than it sounds — the things that break regex-based SQL formatters are all inside tokens. A column aliased 'from where', an apostrophe inside a string, a semicolon in a comment, a T-SQL bracketed identifier containing a reserved word: all of them survive here untouched, because the formatting rules never see inside a token. The minifier is built the same way and deliberately does no final tidying pass over the output, since a whitespace regex across a finished query collapses the spaces inside your string literals and changes your data without telling you. Nothing is uploaded, which matters when the query you are formatting came from production.

What each part of the output does

ElementTreatment
SELECT, FROM, WHERENew line at the current indent level
GROUP BY, ORDER BYRecognised as one clause, never split
JOIN … ONIndented one level under FROM
AND, ORIndented as continuations of their clause
( … )Raises the indent, so subqueries nest visibly
IdentifiersCase preserved exactly as written
'string literals'Never modified, inside or out

When to use it

  1. Make a one-line query from a log or an ORM readable.
  2. Standardise formatting before committing a migration or a view.
  3. Understand someone else's query by seeing its clause structure.
  4. Spot a missing join condition by the shape of the formatted output.
  5. Compress a formatted query back to one line for a config value.

How to Use

  1. Paste your SQL, however badly formatted.
  2. Pick a dialect, keyword case and indent size.
  3. Read the formatted output, or switch to minify for one line.
  4. Copy the result.

Features

  1. Tokenised parsing — strings, comments and quoted identifiers are safe
  2. Clauses, joins and conditions each on their own line
  3. Subqueries indented by parenthesis depth
  4. Keyword casing that leaves identifiers alone
  5. Five dialects with the right identifier quoting
  6. Minify that does not touch string contents
  7. 100% client-side — production queries stay private

FAQs

Will it break my query?

It should not. Strings, quoted identifiers and comments are tokenised before any rule runs, so their contents are never touched — a column aliased 'select from where' comes out exactly as you wrote it. Formatting only inserts and removes whitespace between tokens; it never rewrites them.

Does the dialect setting matter?

Mainly for quoting. T-SQL uses square brackets for identifiers, MySQL uses backticks, and standard SQL uses double quotes — picking the right dialect means those are recognised as identifiers rather than parsed as something else. The clause structure is the same across all five.

Why are my identifiers not uppercased?

Deliberately. Only recognised SQL keywords are cased; table and column names keep exactly the capitalisation you gave them. Uppercasing identifiers would be wrong on any case-sensitive database and unhelpful everywhere else.

What does minify do to comments?

Removes them, since the point of minifying is a single compact line. String literals are kept byte-for-byte — including any whitespace inside them, which is the part most minifiers get wrong.

Can it format a whole migration file?

Yes. Statements are separated at semicolons and each is formatted independently, with a blank line between them.

Is my SQL uploaded?

No. Everything runs in your browser. Queries often contain table names, schema details and sometimes literal customer data — none of it is sent to a server, logged, or stored.

Technical Details

The query is tokenised before any formatting rule runs, which is the difference between a formatter that works and one that corrupts your query. Everything that trips up regex-based formatters lives inside a token: a keyword-looking word inside a quoted string, an apostrophe escaped by doubling or by a backslash, a semicolon inside a comment, a bracketed identifier in T-SQL that happens to contain a reserved word. The tokeniser captures each of those whole, so the casing and line-breaking rules never see inside them. Formatting then walks the token stream: top-level clauses start a new line at the current depth, joins and their ON conditions sit one level in under FROM, AND and OR are indented as continuations, and parentheses raise and lower the indent so subqueries nest visibly. Keyword casing is applied only to words matched against the keyword set, so identifiers keep the capitalisation you gave them, and preserve mode keeps multi-word clauses exactly as typed rather than normalising them. The minifier is built purely from tokens with no final tidying pass over the finished string — running a whitespace regex across the output would collapse the spaces inside your string literals and quietly change the data.

Developer Tools

Developer Tools

  • CSS Formatter
  • HTML Formatter
  • LLM Token Counter
  • .gitignore Generator
  • Dummy Data Generator
  • RAID Calculator
  • Download Time Calculator
  • JSON Formatter