How To Guide

How to Format SQL Online — Free SQL Beautifier (Postgres, MySQL, SQLite)

Format and beautify SQL queries online — proper indentation, capitalized keywords, aligned clauses. Supports Postgres, MySQL, SQLite, SQL Server syntax. Free, no signup.

Why formatting matters for SQL specifically

A 20-line SQL query is often harder to understand than a 200-line function in most languages. Joins across three tables, filters in WHERE, grouping, window functions, subqueries — when these are jammed on one line with inconsistent capitalization, even the author needs a minute to re-parse. Consistent formatting turns that into "read once, understand."

What the SQL formatter does

  • Uppercases reserved keywordsSELECT, FROM, WHERE, JOIN, ON
  • Aligns clauses vertically — one keyword per line, easy to scan
  • Indents nested subqueries consistently
  • Breaks long SELECT lists one column per line when they exceed a threshold
  • Preserves your exact string literals and comments — no accidental semantic changes

Example transformation

-- Before
select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.created_at > '2025-01-01' group by u.id, u.email having count(o.id) > 5 order by orders desc;

-- After
SELECT
  u.id,
  u.email,
  COUNT(o.id) AS orders
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.created_at > '2025-01-01'
GROUP BY u.id, u.email
HAVING COUNT(o.id) > 5
ORDER BY orders DESC;

Dialect support

DialectNotes
PostgresDefault; supports CTEs, window functions, arrays, JSONB operators
MySQLBacktick identifiers handled; USE statements recognized
SQLiteConcise syntax; bare-bones but complete
SQL Server (T-SQL)Square-bracket identifiers; TOP instead of LIMIT
MariaDBMySQL-compatible; extra analytical functions

Pair with explain plans

Formatting doesn't make a query fast — it makes it readable. For actual performance work, run EXPLAIN ANALYZE (Postgres) or EXPLAIN (MySQL) and inspect the plan. A formatted query is easier to pattern-match against indexing advice.

Related tools

For JSONB and JSON columns in Postgres, pretty-print the JSON with JSON formatter. For comparing two query versions side-by-side (e.g., before and after refactoring), diff checker highlights what changed.

Featured Tools

Try these free tools directly in your browser — no sign-up required.

how to format sql sql formatter online sql beautifier pretty print sql format sql query

Explore 300+ Free Tools

Utilko has tools for developers, writers, designers, students, and everyday users — all free, all browser-based.