DevToolbox

SQL Formatter

Format and beautify SQL queries

InputPaste or type SQL
Loading...
Output

Output will appear here

Related tools

What is SQL formatting?

SQL formatting structures database queries with capitalized keywords (SELECT, FROM, WHERE), proper indentation for subqueries and joins, and consistent line breaks. This tool supports multiple SQL dialects and processes everything in your browser.

Why readable SQL matters

A SQL formatter re-prints a query with keywords aligned and each major clause on its own line, so a long statement becomes easy to read and review. When SELECT, FROM, JOIN, WHERE, GROUP BY, and ORDER BY each start a new line, the shape of the query — and any missing or misplaced clause — is immediately visible.

Formatting is especially valuable for the generated or concatenated SQL that comes out of ORMs and logs as a single dense line.

Formatting does not change results

Re-formatting only adjusts whitespace and letter case of keywords; it never changes what the query does. The formatted statement returns exactly the same rows as the original. Minifying collapses the query back to a single line, which is handy for embedding it in code or a configuration value.

Readable SQL in code review

Formatting matters most for the long queries that are hardest to review. Placing each clause on its own line and aligning keywords lets a reviewer confirm the joins and filters at a glance, which catches logic errors before they reach production.

How to format a SQL query

  1. 1Paste your query. Paste a SELECT, INSERT, UPDATE, or other statement into the input.
  2. 2Click Format. Clauses are placed on separate lines and keywords are aligned. Use Minify to collapse it to one line.
  3. 3Copy the result. Copy the formatted query into your editor, migration, or report.

Examples

Format a joined query

Input

select u.name, count(o.id) from users u join orders o on o.user_id=u.id where u.active=1 group by u.name

Output

SELECT u.name, COUNT(o.id)
FROM users u
JOIN orders o ON o.user_id = u.id
WHERE u.active = 1
GROUP BY u.name

Minify a formatted query

Input

SELECT id
FROM users
WHERE active = 1

Output

SELECT id FROM users WHERE active = 1

Clause order in a SELECT

The logical order SQL clauses appear in.

ClausePurpose
SELECTColumns to return
FROMSource tables
JOIN … ONCombine related tables
WHEREFilter rows
GROUP BYAggregate into groups
HAVINGFilter groups
ORDER BYSort the result
LIMITCap the number of rows

Frequently asked questions

Does formatting change what my query returns?+

No. Only whitespace and keyword casing change. The formatted query is logically identical and returns the same rows.

Which SQL dialects are supported?+

Standard SQL keywords and structure are formatted, which covers the common syntax of engines like PostgreSQL, MySQL, SQL Server, and SQLite.

Will it uppercase my keywords?+

Yes, keywords such as SELECT and WHERE are capitalised for readability, while your table and column names are left as written.

Can I minify a query?+

Yes. Minify collapses a formatted statement back to a single line, which is useful for embedding SQL in application code.

Is my query private?+

Yes. Formatting runs in your browser, so your SQL and any data in it never leave your machine.

Is it free?+

Yes — free with no limits.

Does it change my table or column names?+

No. Only keywords are capitalised and clauses are laid out; your identifiers are left exactly as written.