SQL prettify and format
Format and prettify your SQL queries online (it supports various SQL dialects).
About SQL prettify and format
Formats SQL into a consistently indented, readable layout, with the dialect of your database (PostgreSQL, MySQL, SQL Server, BigQuery and more), keyword casing and indent style of your choice. Powered by the sql-formatter library.
When you would use it
- Making a long query copied from logs, an ORM or a BI tool readable before debugging it.
- Normalising the style of queries before committing them or pasting them into a review.
- Cleaning up a one-line query generated by a script.
How to use it
- Choose the dialect that matches your database so its specific keywords and syntax are recognised.
- Pick the keyword case (UPPERCASE, lowercase or preserve) and the indent style.
- Paste the query and copy the formatted result.
Things worth knowing
- The formatter only rearranges whitespace and keyword casing. It never changes the meaning of the query, and it does not validate it against a schema.
- Choosing the wrong dialect can misread dialect-specific syntax (for example T-SQL brackets or PostgreSQL casts with ::) and produce odd line breaks. Standard SQL is a safe fallback.
- Tabular indent styles align keywords in a column, which some teams prefer for long SELECT lists; Standard is the conventional nested layout.
- Several statements separated by semicolons are formatted one after the other.
Frequently asked questions
- Why does the output look wrong around a specific construct?
- Most likely the dialect does not match. Switch to the dialect of your database; if the construct is unusual, Standard SQL may format it more predictably.
- Does formatting change how the database executes the query?
- No. Whitespace and keyword case are irrelevant to the database. String literals and identifiers are left untouched, so the query behaves exactly the same.