Developer SQL Query Formatter

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 queryStandard SQLMySQLPostgreSQLSQL Server
Backtick names: `order`.idformatsformatserrorerror
Bracket names and variables: [Order].[Total Amount], @statuserrorerrorerrorformats
Casts, JSON operators, placeholders: created_at::date, meta->>'coupon', $1errorerrorformatserror

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