Skip to content
ToolZone

SQL Formatter

Beautify a compact or messy SQL query into a readable, properly indented structure, making complex queries easier to review and debug.

Runs in your browser. Nothing you enter or upload leaves your device.

Keywords
Indent
Formatted SQL…

Strings, quoted names and comments are kept exactly as written. Works with MySQL, PostgreSQL, SQLite and SQL Server syntax.

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the SQL Formatter

Queries copied from logs, ORMs, or application code usually arrive as one long line that is hard to read. This SQL Formatter breaks the query into one clause per line, uppercases the main keywords, and puts each comma-separated item on its own indented line.

How it works

The query is split into tokens: quoted strings, quoted identifiers, comments, punctuation and words. Because strings and comments are separate tokens, commas, keywords and spaces inside them are never touched. Keywords are then converted to the case you choose.

The formatter writes each clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOINs and so on) on a new line with its contents indented beneath it, puts AND and OR conditions on their own lines (except inside BETWEEN), and gives each comma-separated column its own line. A subquery in parentheses gets its own indented block. Minify uses the site's SQL minifier, which also keeps strings intact.

How to use

  1. 1

    Choose Format or Minify.

  2. 2

    Pick the keyword case and indentation.

  3. 3

    Paste your SQL or open a .sql file.

  4. 4

    Copy the result or download it. Your options are kept in the page link.

Worked examples

Tidying a SELECT query

A query copied from an application log.

Input
select id, name from users where active = 1 and age > 18 order by name
Result
SELECT id, name FROM users WHERE active = 1 AND age > 18 ORDER BY name

Each clause starts a new line, keywords are uppercased, and the second selected column is indented under SELECT.

Formatting an UPDATE statement

Making a multi-column update easier to review before running it.

Input
update users set name = 'Ann', age = 30 where id = 7
Result
UPDATE users SET name = 'Ann', age = 30 WHERE id = 7
Limitations
It formats by structure, not by a full grammar, so unusual dialect syntax (procedures, PL/pgSQL blocks) may format plainly. CASE expressions stay on one line. Function argument lists are kept on one line.
Assumptions
The input is a single SQL statement or a few simple statements. The query does not rely on whitespace inside string literals.
Privacy
Formatting happens in your browser; your query is not sent to a server or stored.

Frequently asked questions

Does this work with different SQL dialects?+

Mostly yes. It works by recognizing common keywords, so standard queries in MySQL, PostgreSQL, SQLite, or SQL Server format the same way. Dialect-specific keywords not on its list are left as they are.

Will formatting change how my query executes?+

No. Only whitespace and keyword case change, and strings, quoted identifiers and comments are kept exactly as written.

Does it uppercase all keywords?+

It changes the case of SQL keywords and common functions such as COUNT and COALESCE, to UPPER or lower as you choose, or leaves them as typed. Table and column names keep their case.

Can it minify a query too?+

Yes. Click Minify to collapse the query onto one line and remove spaces around parentheses and commas.

How are joins formatted?+

It isn't any more. Compound joins like LEFT JOIN and INNER JOIN stay together on one line, with their ON condition indented below.

Related tools