SQL format

Take a SQL statement that arrived as one long line and format it into something readable.

Runs in your browser — nothing you type here is sent anywhere.
Query
18
lines out
286367 chars
4-space indent
Formatted
SELECT
    o.id,
    o.total,
    c.name AS customer,
    (
        SELECT
            COUNT(*)
        FROM items i
        WHERE i.order_id = o.id
    ) AS items
FROM orders o
JOIN customers c
    ON c.id = o.customer_id
    AND c.tier <> 'select -- all'
WHERE o.total > 100
    AND o.created_at BETWEEN '2024-01-01' AND '2024-12-31'
ORDER BY o.total DESC
LIMIT 20;

Tokenised before anything moves, so a string literal, a quoted identifier or a comment is never reformatted — the seeded query hides the words select and -- inside a literal and both come through untouched. Clauses start a line, the select list and every ON / AND / OR sit under theirs, and a parenthesised subquery indents a level and closes back out. Upper case is applied to keywords only, never to identifiers or to what is inside quotes. Minify collapses whitespace outside literals and keeps the newline after a -- comment, which would otherwise swallow the rest of the query.

SQL logged by an ORM comes out as a single line with every clause running together. Reading a join condition or working out where a subquery ends is genuinely difficult in that form.

Keywords are placed onto their own lines, joins and conditions indented, and nesting made visible. Case is normalised so the structure stands out, and comments and string literals are preserved untouched.

What people open it for

In the terminal

tools sqlfmt

Every utility is also a command in the desktop's shell.

More text tools

Open the full desktop, with all 47 utilities