SQL Formatter & Beautifier

Paste messy SQL — get clean, indented output with clause line-breaks and keyword casing.

The SQL Formatter beautifies messy or machine-generated SQL into clean, readable queries — each major clause on its own line, columns broken out, and keywords cased the way you prefer. It also minifies SQL to a single line. Ideal for queries copied from ORMs, application logs and query builders.

  • Clause line-breaks for SELECT, FROM, JOIN, WHERE, GROUP BY…
  • Uppercase, lowercase or preserve keyword casing
  • Minify SQL down to a single line
  • Dialect-agnostic and 100% private

What the SQL Formatter Does

The formatter tokenizes your SQL — correctly handling quoted strings, identifiers and comments — then reflows it: major clauses like SELECT, FROM, WHERE, JOIN, GROUP BY and ORDER BY each start on their own line, column lists break after commas, and parentheses are indented by nesting depth. Keyword casing is configurable and everything runs locally in your browser — it reflows structure rather than validating a specific database dialect.

How to Format SQL Online

  1. 1Paste your raw, minified or ORM-generated SQL into the input panel
  2. 2Choose UPPER, lower or Keep for keyword casing
  3. 3Click Format to reflow it, or Minify to collapse it to one line
  4. 4Copy or download the result

Example

Input (single line, from an ORM log):

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 = true and o.created_at > '2024-01-01' group by u.id, u.name having count(o.id) > 3 order by orders desc limit 10;

Output (formatted, UPPER keywords):

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 = true
  AND o.created_at > '2024-01-01'
GROUP BY u.id, u.name
HAVING COUNT (o.id) > 3
ORDER BY orders DESC
LIMIT 10;

Keyword Casing Options

ModeSELECT becomesBest for
UPPERSELECTTraditional SQL style guides, most style guides and textbooks
lowerselectModern codebases that prefer lowercase SQL
Keep(unchanged)Preserving the exact casing already in the query

Features

Clause line-breaks

SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY each start a new line.

Configurable keyword casing

UPPER, lower or Keep — applied only to recognized SQL keywords.

Minify to one line

Collapse a query to a single line with comments stripped, for logs or embedding in code.

Nested subqueries

Parentheses are indented by nesting depth, so subqueries stay readable.

Preserves literals exactly

Quoted strings, quoted identifiers and comments are never altered.

100% private

Formatting runs entirely in your browser — safe for production queries and schemas.

Who Uses This

  • Backend engineersclean up single-line queries logged by an ORM (Prisma, Sequelize, ActiveRecord, Hibernate) before debugging them.
  • Code reviewersreformat a teammate's query to the team's keyword-casing convention before approving a PR.
  • Data analyststidy up ad-hoc queries pulled from a BI tool or query builder before sharing them.
  • Students and educatorsuse consistent indentation to make JOIN and subquery structure easier to teach and read.

Frequently Asked Questions

Yes. The formatter is dialect-agnostic — it formats standard SQL syntax common to MySQL, PostgreSQL, SQL Server, SQLite and most engines. It reflows structure rather than validating dialect-specific features.

No. It's a formatter, not a query validator — it reflows structure and casing but doesn't check table names, column references or dialect-specific syntax for correctness.

Yes. Click Minify to collapse the query onto a single line with comments removed — useful for embedding SQL in code, config, or one-line log statements.

No. Quoted strings, quoted identifiers and comments are preserved exactly; only keywords are re-cased and whitespace is reflowed.

Yes. Parentheses are indented according to their nesting depth, and each JOIN clause starts on its own line, so multi-join queries with subqueries stay readable.

All of them. INSERT ... VALUES, UPDATE ... SET, and DDL statements like CREATE TABLE are reflowed using the same clause and comma rules as SELECT queries.

No. All formatting happens in your browser with JavaScript — safe for production queries and schemas.

Related Tools