SQL Query Formatter & Beautifier

Paste a messy SQL query and get it reformatted with clause line breaks, indentation, and uppercase keywords — entirely in your browser.

Formatted query


      

Reformats whitespace, line breaks, and keyword casing for common SELECT / INSERT / UPDATE / DELETE statements. It does not validate SQL syntax, does not understand every database's dialect-specific extensions, and does not re-indent deeply nested subqueries beyond one level — always check the output against your own database before running it.

About this tool

How to use it

  1. Paste your SQL query into the box — it comes pre-loaded with a sample query so you can see the formatting immediately.
  2. Toggle 'Uppercase keywords' on or off, and pick 2-space, 4-space, or tab indentation.
  3. Press Format SQL, or just keep typing — the output updates live.
  4. Press Copy to copy the formatted query to your clipboard.

Why it matters

A query written on one long line, or pasted out of a log file with inconsistent spacing, is hard to scan for the actual logic — which columns are selected, which tables are joined, which conditions gate the WHERE clause. Breaking each major clause onto its own line, indenting continuations, and consistently casing keywords turns a wall of text back into something a reviewer (including your future self) can read at a glance.

When to use it

Useful when pasting a query out of application logs, a slow-query report, or a colleague's message that arrived as one unbroken line, when preparing a query for a code review or documentation, or when standardizing keyword casing across a codebase that mixes SELECT and select inconsistently.

Good to know

This reformats whitespace, line breaks, and keyword casing — it does not parse or validate SQL syntax, so an invalid query is reformatted exactly as invalid as it started. It targets common SELECT / INSERT / UPDATE / DELETE statements across the SQL dialects most sites share (standard clauses, joins, common functions); dialect-specific extensions (e.g. PostgreSQL's DISTINCT ON, SQL Server's TOP, vendor-specific hints) are passed through as plain text rather than specially formatted. Subquery indentation is limited to one level of nesting inside parentheses — very deeply nested queries may need manual touch-up. Nothing typed here is sent anywhere; formatting runs entirely in your browser.

Common questions

Does this tool validate whether my SQL is correct?

No — it only reformats whitespace, indentation, and keyword casing. It has no SQL parser or database connection behind it, so a query with a typo or a missing table will be reformatted exactly as broken as it was pasted in.

Which SQL dialect does this support?

It's built around the clauses and syntax shared by most SQL dialects (MySQL, PostgreSQL, SQLite, SQL Server, and similar) — standard SELECT/FROM/WHERE/JOIN/GROUP BY/ORDER BY/HAVING, plus INSERT/UPDATE/DELETE. Dialect-specific keywords or extensions are left as-is rather than specially reformatted.

Why didn't my deeply nested subquery get fully re-indented?

The formatter indents one level inside parentheses, which covers most subqueries and function calls, but a query with several levels of nested subqueries may need some manual adjustment beyond that first level.

Is my SQL sent to a server to be formatted?

No — everything runs in your browser with plain JavaScript. Nothing you paste here is transmitted, logged, or stored anywhere, which also means it's safe to paste queries that reference real table or column names.

Can I format multiple statements separated by semicolons at once?

Yes — paste multiple semicolon-terminated statements and each one is reformatted in turn, with a blank line separating them in the output.