Skip to content
epitometool

SQL formatter

Code formatters

Format SQL queries with dialect-specific rules.

Updated

SQL input

Options

Formatted

SELECT u.id,
  u.name,
  count(o.id)AS order_count
FROM users u
LEFT JOIN orders o
ON o.user_id = u.id
WHERE u.created_at > '2024-01-01'
  AND u.is_active = true
GROUP BY u.id,
  u.name
HAVING count(o.id)> 5
ORDER BY order_count desc
LIMIT 10;

Quick start

How to format SQL for readability

Paste a one-line query, get clean indented SQL ready for code review or docs.

  1. Step 1
    Paste SQL

    Drop your one-line or messy SQL into the textarea.

  2. Step 2
    Pick options

    Choose indent width (2 / 4 typical) and whether keywords should be UPPERCASE or lowercase.

  3. Step 3
    Copy

    One-click copy to paste into your editor, pull request comment or design doc.

In-depth guide

SQL formatter — readable queries for code review

Paste a one-line SQL blob — the kind your ORM logs — and get back a clean multi-line query with each clause indented. Useful for code review, query debugging, or preparing snippets for documentation. Runs in your browser.

Layout conventions

  • Major clauses (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT) each on their own line.
  • Joins on their own line with ON indented.
  • Multiple AND / OR conditions stacked and indented under WHERE.
  • Each select column on its own line.
  • Subqueries ((SELECT …)) indented one level deeper.

When SQL formatting matters

  • Code review — long one-liners are hard to scan. Diffs are clearer when each column or condition is on its own line.
  • Query tuning — easier to spot a missing JOIN condition or a CROSS JOIN when the structure is laid out.
  • Debugging ORM-generated SQL — what your ORM logs is usually unformatted. Paste it here to read it.
  • Documentation — formatted queries copy nicely into markdown and design docs.

Limits

  • This is a layout tool — not a linter or query rewriter.
  • Dialect-specific keywords beyond the common list pass through unchanged.
  • Comments inside the query are stripped. Add them back after formatting if needed.
  • Multi-statement scripts are formatted per statement, separated by blank lines.

Frequently asked questions

Does this tool send my SQL anywhere?

No. Formatting runs in your browser. Safe to paste queries that touch sensitive table or column names.

Is this a real SQL parser?

No — it's a keyword-aware layout tool. It tokenises, recognises common clauses, puts each on its own line and indents subqueries. It doesn't validate syntax or understand all dialect-specific extensions.

Which SQL dialects are supported?

Standard ANSI-ish SQL plus the most common PostgreSQL / MySQL / SQLite keywords. Dialect-specific syntax (PIVOT, CONNECT BY, MERGE…) generally passes through but may not lay out ideally.

Does it handle comments?

Block comments /* … */ and line comments -- … are stripped during tokenisation. We don't preserve comments. Add them back after formatting if you need them.

Why are some of my keywords not capitalised?

Recognition is keyword-list based. Function names (COUNT, SUM, NOW) aren't always in the list. If a token isn't in our keyword set, it passes through with its original case.

Will it reformat my CREATE TABLE statement?

Yes — column definitions inside parens get each on their own line. CHECK constraints and FOREIGN KEY references stay readable for most cases.

Keep exploring

More tools you'll like

Hand-picked utilities that pair well with the one you're on — all free, client-side, and zero-signup.