SQL Formatter

Format and beautify SQL queries for readability.

SQL Query

Formatted SQL

About the SQL Formatter

The SQL Formatter re-indents a query so the clauses line up and nested logic is visible. Paste a one-line query and it returns the same statement with keywords, conditions and subqueries on their own lines.

Formatting only changes whitespace. The statement sent to the database is identical, so a query that was correct before is correct after, and one that was wrong stays wrong. That is the point: you make it readable without changing what it does.

The gain is largest with long WHERE clauses and joins. Once each condition sits on its own line, a missing AND or a misplaced OR becomes obvious, which is how most accidental cross joins get caught.

Common questions about SQL Formatter

Does formatting change my query?

No. Only whitespace changes, so the statement behaves exactly as before.

Which SQL dialects are supported?

The formatter handles standard SQL. Vendor-specific syntax generally passes through unchanged.

Will it fix a broken query?

No. It formats, it does not parse for correctness. Use EXPLAIN or your database to check validity.

Does it handle subqueries?

Yes, nested statements are indented inside their parentheses.

Can it minify instead?

This page formats. For a single-line query, a text editor's join-lines command is usually enough.

Is my query sent anywhere?

No. Formatting runs in the browser, so schema names and data stay local.

Related Tools in Developer Tools

JSON FormatterBase64 Encoder/DecoderURL Encoder/Decoder