SQL formatter

Paste a query to format it with clean indentation and consistent keyword case. Pick your database so its syntax is understood. Your SQL stays in your browser.

Loading formatter…

What the SQL formatter does

It parses your query and rewrites it with one clause per line (SELECT, FROM, JOIN, WHERE, GROUP BY…), indented column lists and subqueries, and consistent keyword case. The meaning of the query does not change.

Supported databases

Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL, DuckDB, ClickHouse and Trino. Choosing the right dialect matters for things like [brackets] in T-SQL, backticks in MySQL and BigQuery, and $1 parameters in PostgreSQL.

Minify

Minify removes comments and collapses whitespace onto one line, leaving string literals and quoted names untouched (including backslash escapes in MySQL-style dialects and $$ strings in PostgreSQL). It is handy for pasting a query into code or a log search.

Formatting uses the open-source sql-formatter library, running in your browser.

Frequently asked questions

Why does it say it could not parse my SQL?
The query uses syntax from a different dialect, or it is incomplete. Choose your database from the list and try again.
Does formatting change what my query does?
No. Only whitespace, line breaks and (if you choose) keyword case change.
Can I format several statements at once?
Yes. Separate them with semicolons; each starts on a new line with a blank line between them.
Is my SQL uploaded?
No. The formatter runs in your browser, so table names and data in your query stay on your device.