SQL Query Formatter
Paste messy or minified SQL and get clean, properly indented output.
How to use this tool
Paste a query and pick the database it was written for. Each clause goes on its own line, columns and conditions are indented under it, and keywords are written in capitals. If the query can't be parsed, you get the line and column where parsing stopped instead of output.
Which dialect accepts what
A "Parse error: Unexpected …" message usually means the dialect is wrong, not the query. Tested with the formatter this page uses:
| Syntax in the query | Standard SQL | MySQL | PostgreSQL | SQL Server |
|---|---|---|---|---|
Backtick names: `order`.id | formats | formats | error | error |
Bracket names and variables: [Order].[Total Amount], @status | error | error | error | formats |
Casts, JSON operators, placeholders: created_at::date, meta->>'coupon', $1 | error | error | formats | error |
One thing that can look like a change
Keyword capitals apply to any word the dialect treats as a keyword, including one you used as a name. In select created_at::date as day, the alias comes out as AS DAY. Unquoted names aren't case-sensitive in PostgreSQL, MySQL or SQL Server, so the query still returns a column that reads as day in PostgreSQL, and nothing else about the query changes. If a name must keep its exact case, quote it in the original.
Frequently Asked Questions
Can I paste several statements at once?
Yes. Statements ending in semicolons are formatted one after another, with a blank line between them, so a migration file or a batch of queries from a log can be pasted as a whole.
Is my SQL query uploaded anywhere?
No. Formatting happens entirely in your browser using a JavaScript SQL parser — your query, including any table names, column names, or embedded values, is never sent to a server.
Does formatting change comments, strings or names in my query?
Comments stay where they were (a trailing -- comment stays on its line), and text inside quotes, including quoted names such as "Order", is left exactly as written. Unquoted names keep their case unless they are also keywords in the chosen dialect: a column called user comes out as USER. Only case and whitespace change, so the query runs the same.
Related Tools
Related Blog Posts
How to Format and Read Messy SQL Queries
A one-line report query, formatted step by step, and the AND/OR precedence bug the formatting exposes, plus why picking the right SQL dialect matters and a LEFT JOIN rule worth memorising.
Read moreHow to Use QR Codes for Marketing, Docs, and Events
How much a QR code can hold, why a shorter or uppercase link gives a code that scans more easily, what error correction actually protects against, and how to size one for print.
Read moreHEX, RGB and HSL: How the Conversions Work and Where They Round
#4F46E5 converted to RGB and HSL step by step, why 89.4% of all colours change when copied as whole-number HSL, why HSL lightness is not brightness (yellow and blue at 50% differ eightfold in contrast), and the alpha that hex can't write exactly.
Read more