Skip to main content

SQL Formatter

Turn one-line SQL into clean, indented queries — supports MySQL, PostgreSQL, SQLite and more, with optional keyword casing.

One line in, a readable query out

A join with grouping, all crammed onto one line.

Input
select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=1 group by u.id,u.name having count(o.id)>2 order by orders desc
Output
select
  u.id,
  u.name,
  count(o.id) as orders
from
  users u
  left join orders o on o.user_id = u.id
where
  u.active = 1
group by
  u.id,
  u.name
having
  count(o.id) > 2
order by
  orders desc

Beyond the line breaks, notice the spaces inserted around = and >: o.user_id=u.id became o.user_id = u.id. The keywords were deliberately left lowercase — case is a style choice and lives in its own option, indentation is not.

What is a SQL formatter?

SQL copied out of code, a log or an ORM often arrives as one long, unreadable line. This SQL formatter lays it out with proper indentation and line breaks: SELECT, FROM, WHERE and JOIN each get their own section so you can see at a glance what the query does. It supports MySQL, PostgreSQL, SQLite and other dialects, and runs entirely locally in your browser.

How to use

  1. Paste your SQL into the input box.
  2. Choose the database dialect and keyword case.
  3. Click "Format" and copy the tidy result back into your code or tool.

Common use cases

  • Lay out a long query printed by an ORM or framework to debug it.
  • Standardize your team’s SQL style (indentation, uppercase keywords).
  • Working with JSON or other data too? Use the JSON formatter or JSON ⇄ CSV.

Why does picking the right "dialect" change the result?

SQL has an ANSI standard, but every database bolts on its own syntax sugar, so a formatter needs to know which dialect you're using to lay it out correctly. The classic example is identifier quoting: MySQL uses backticks `col`, while PostgreSQL and standard SQL use double quotes "col". Then there's LIMIT (MySQL/SQLite) vs TOP (SQL Server), PostgreSQL's :: type casts, BigQuery's backtick table names, and more. Pick the wrong dialect and the tool may treat these as plain strings or operators, so the indentation comes out odd. Before you paste, choose the database you actually use in the "Dialect" dropdown. One misconception worth clearing up: formatting is not validation, and it never runs your query — it only adjusts whitespace and indentation, so it won't tell you whether a table exists or whether the syntax runs on a real database. To clean the data itself, use the JSON formatter for JSON or JSON ⇄ CSV for tables.

Will it change my keyword casing?

Not by default, and that is verifiable character by character. A lower-case query formats to select * from users where id = 1, while the same shape typed in upper case gives SELECT id, name FROM t WHERE a = 1 AND b = 2 — whatever casing goes in comes back out. The default is preserve, because re-casing keywords is a house style rather than a correctness fix, and changing it silently would make the diff of a formatting-only commit unreviewable. What it does change is the line breaks: one clause per line, operands indented beneath.

Frequently Asked Questions

Which databases are supported?

It supports Standard SQL plus common dialects: MySQL, PostgreSQL, SQLite, MariaDB and BigQuery. Keywords and syntax differ slightly between dialects, so picking the right one gives more accurate formatting.

Does it change my query logic?

No. Formatting only adjusts whitespace, line breaks and indentation (plus optional keyword case). It never touches your tables, columns or conditions — the query does exactly the same thing.

Can it standardize keyword case?

Yes. You can preserve the original, force UPPERCASE (SELECT, FROM) or lowercase, so your team’s SQL style stays consistent.

Is my data uploaded?

No. Formatting happens locally in your browser; your SQL never leaves your device.

Related reading

Why Formatting SQL Matters (and What a Formatter Does) →

Embed this tool

Add this tool to your own website or blog for free — just copy and paste the code below (it includes a link back to this site).