Developer

SQL Formatter

Format SQL with clause-per-line layout and dialect-aware tokenizing. Layout only — nothing is ever executed.

Runs entirely in your browser. Nothing you paste is uploaded.

0 characters · 0 bytes

This runs entirely in your browser. Nothing you paste is sent to us or to anyone else.

How to use it

  1. Paste your text into the box marked "Your SQL"Paste a query — a long one with joins and subqueries is where this earns its keep. Everything happens inside your browser — nothing is uploaded, so there is nothing for us to store, log or lose.
  2. Read the result as it updatesThere is no button to press. The formatted query appears immediately. The output recomputes every time you change the text or one of the options above it.
  3. Choose your DialectGeneric, PostgreSQL or MySQL / MariaDB. It changes how quoting and dialect-specific keywords are handled, so picking the right one avoids a formatter that mangles an identifier it did not recognise.
  4. Set the Keywords caseUPPERCASE, lowercase or as written. Leaving them as written is the right choice when you are tidying somebody else's file and do not want a diff full of case changes.
  5. Read it as formatting onlyThis lays a query out; it does not check that it is valid against your schema, and it never changes what the query does.
  6. Copy or download the resultThe buttons under the output put it on your clipboard or save it as a file, and each one says exactly what it will copy or download. Any note about something the tool changed or deliberately left alone is shown with the result rather than hidden.

About this tool

Format a SQL query into the layout experienced people read fastest: one major clause per line, select-list items and conditions indented beneath their clause, subqueries indented inside their parentheses, keywords cased consistently.

The formatter is layout-only by design. Tokens are never added, removed or reordered — the single change beyond whitespace is keyword casing, and only when you choose it. And it never executes anything: this is text formatting in your browser, not a database connection. There is no engine here to run a query against.

Understanding the result

Major clauses (SELECT, FROM, WHERE, GROUP BY, each JOIN…) start their own lines. AND, OR and ON are indented one level under the clause they belong to, which is what makes a long WHERE readable.

Function arguments and IN lists stay inline; a parenthesis that opens a subquery gets a full indented block instead. Comments survive on their own lines.

The dialect matters more than it looks: it sets the quoting rules the tokenizer applies. Backticks and # comments are MySQL, [brackets] are SQL Server, $$dollar quotes$$ and nested block comments are PostgreSQL, and a backslash inside a string is an escape in MySQL but a literal character in PostgreSQL. Generic accepts all of them at once — the right default for a query of unknown origin.

Example

Input

select u.id, count(*) as n from users u left join orders o on o.uid = u.id where u.active = 1 group by u.id order by n desc

Output

SELECT u.id,
  COUNT(*) AS n
FROM users u
LEFT JOIN orders o
  ON o.uid = u.id
WHERE u.active = 1
GROUP BY u.id
ORDER BY n DESC

Limitations

  • This formats; it does not validate SQL grammar. A query with a typo in a keyword formats as if the typo were an identifier — only lexical errors (an unclosed string, comment or parenthesis) are reported, each with its position.
  • Type names (int, varchar…) are treated as identifiers, so keyword casing does not touch them.
  • Procedural blocks (stored procedures, triggers, BEGIN…END bodies) are formatted with the same clause rules, which is serviceable but not specialised — a dedicated PL/pgSQL or T-SQL formatter will lay those out better.
  • Very long queries format fine, but this is a reading aid, not a linter: it will not warn about SELECT *, missing indexes or Cartesian joins.

Questions

Is my query uploaded or executed anywhere?

No. The whole tool is JavaScript running on your device — there is no request to send. You can confirm it by opening your browser's network tab, or by disconnecting from the internet and using the page anyway.

Which dialect should I pick?

If you know the engine, pick it — the rules for quotes, comments and escapes then match exactly. If you are reading a query of unknown origin, Generic accepts every engine's quoting at once. The one case Generic gets wrong is syntax that means something different per engine, such as # starting a comment in MySQL but an identifier in SQL Server.

Why did my query keep its lowercase table names?

Only keywords are re-cased. Identifiers — table, column and alias names — are left exactly as written, because on some systems (MySQL on Linux, quoted identifiers in PostgreSQL) their case is significant.

Can it format a whole migration file?

Yes — statements separated by semicolons are formatted one after another with a blank line between them. DDL (CREATE TABLE and friends) uses the same clause rules, which keeps column definitions readable.

Last updated 2026-08-16.

Related tools