SQL formatter

Beautify and capitalise SQL queries with clean clause wrapping — privately, in your browser.

What an SQL formatter does — and how this one works

A query that runs perfectly can still be a nightmare to read. Pasted from a log, an ORM, or a colleague's Slack message, SQL often arrives as a single unbroken line with random casing. A formatter parses that text and prints it back with consistent keyword casing and one clause per line, so the shape of the query — what it selects, where it joins, how it filters — becomes obvious at a glance. That readability is what lets you spot a missing join condition or an accidental cartesian product before it reaches production.

This tool is quote-aware. Rather than blindly running find-and-replace over your text, it walks the query character by character and tracks when it is inside a single-quoted string, a double-quoted identifier, or a backtick-quoted name. Only the keywords outside those regions are touched — so a literal value like 'order by' stored in a column is never mistaken for a clause and is left exactly as you wrote it.

A worked example

Paste a dense one-liner like this:

select id, email from users where status = 'active' order by created_at desc limit 10;

…and with both options enabled it becomes:

SELECT id, email
FROM users
WHERE status = 'active'
ORDER BY created_at desc
LIMIT 10;

Notice the value 'active' keeps its lower-case casing — it is data, not a keyword — while only the recognised clauses are capitalised and broken onto their own lines.

Logical clause order vs. execution order

Formatting also makes it easier to reason about a query, because SQL does not run in the order you write it. You write SELECT first, but the engine resolves the data sources and filters long before it projects your columns:

ClauseWriting orderExecution orderWhat it does
FROM / JOIN21Picks the source tables and matches rows across them.
WHERE32Filters individual rows before any grouping happens.
GROUP BY43Collapses rows into groups by shared key columns.
HAVING54Filters the grouped results (e.g. COUNT(*) > 5).
SELECT15Projects and computes the final output columns.
ORDER BY66Sorts the finished result set for display.
Privacy note: this formatter runs with no server and no analytics on your input. Your query is tokenised on your own device and exists only in this browser tab until you copy it or close the page — safe for internal schema and table names.

Frequently asked questions

Is my SQL sent to a server?

No. The query is tokenised and reformatted entirely in your browser with JavaScript. Nothing is uploaded, logged or stored, so it is safe to paste queries that reference internal table names, schemas or business logic.

Does formatting change what my query does?

No. The formatter only adds and removes whitespace and changes the case of recognised keywords. It never reorders clauses, edits column names, or touches the text inside quoted strings — so the query you copy out runs identically to the one you pasted in.

Which SQL dialect does it support?

It targets common ANSI-style SQL used by PostgreSQL, MySQL, SQLite, SQL Server and Oracle. It recognises the standard SELECT, INSERT, UPDATE, DELETE and JOIN keywords. Highly dialect-specific syntax (window frames, vendor functions) is left intact rather than rewritten.

Why are some words inside quotes not capitalised?

That is intentional. The tokeniser tracks single quotes, double quotes and backtick identifiers, so a value like 'select' inside a WHERE clause is treated as data, not a keyword, and is left exactly as you typed it.

What do the two options do?

Uppercase keywords converts recognised SQL keywords such as select, from and where to capitals, which is the most common house style. Wrap major clauses puts FROM, WHERE, JOIN, GROUP BY, ORDER BY and similar onto their own lines so the shape of the query is easy to scan.