SQL Formatter

Paste a messy query and get clean, indented SQL with keywords on their own lines.

Runs entirely in your browser. Your query is never uploaded or stored.

How to use this tool

Paste or type your query into the input box. Pick how many spaces you want per indent level and whether keywords should be uppercase or lowercase. Click Format SQL and the cleaned-up query appears in the output box below. Use Copy result to put it on your clipboard, or Clear to start over. Everything happens locally, so even sensitive queries stay on your machine.

How the SQL beautifier works

major clause -> new line at base indent sub-item after a comma -> new line, indented one level keyword -> normalized to UPPER or lower case

This formatter is a lightweight, rule-based SQL beautifier rather than a full SQL parser. It scans the query token by token, recognizes a list of standard keywords, and rewrites the casing you chose. Major clauses such as SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING and ORDER BY are pushed onto their own lines. Columns separated by commas inside a SELECT are placed on indented lines so wide column lists stay readable. Parentheses increase the indent so subqueries and grouped conditions line up neatly. Because it works on plain text, it handles most everyday queries quickly without sending anything to a server.

A real example

Input: select id, name, email from users where active = 1 and country = 'US' order by name

With 4-space indent and uppercase keywords, the output becomes:

SELECT id, name, email FROM users WHERE active = 1 AND country = 'US' ORDER BY name

The single cramped line is now broken into labeled clauses, each column sits on its own indented row, and the AND condition is aligned under WHERE, so the logic is easy to read at a glance.

Common questions

Is this SQL formatter free and private?

Yes. It is completely free and runs only in your browser. The query you paste is never sent to any server, so it is safe to format internal or sensitive SQL.

Which SQL dialects does it support?

It works with the common keywords shared by MySQL, PostgreSQL, SQL Server, SQLite and most other engines. Since it is a text-based beautifier, it indents and cases standard clauses but does not validate dialect-specific syntax.

Can it indent complex queries with joins and subqueries?

It handles JOINs, ON conditions, WHERE logic and parentheses for grouped expressions or subqueries by increasing the indent inside brackets. Very deeply nested queries may need minor manual touch-ups.

Why does it not reformat my comments or strings perfectly?

To stay simple and fast, the formatter focuses on keywords and structure. Quoted strings are kept intact, but inline comments and unusual formatting inside literals are left mostly as-is rather than rewrapped.

Does formatting change what my query does?

No. Formatting only adds whitespace and adjusts keyword casing. The actual logic, table names and values stay the same, so the query returns identical results.