Free Online SQL Formatter
Format and beautify SQL for 12 dialects, or minify it. Choose keyword case and indentation.
SQL input
Formatted SQL
How to use
Paste your SQL, or open a .sql file.
Choose the SQL dialect, keyword case and indentation.
Read the formatted result, or switch to Minify for a compact single-line version.
Copy the result or download it as a .sql file.
Why use this tool
12 SQL dialects
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, Oracle, BigQuery, Snowflake, Redshift, Spark and Db2.
Your style
Uppercase, lowercase or as-written keywords, with 2 or 4 spaces or tabs.
Several queries at once
Statements separated by semicolons are formatted and spaced apart.
Safe minify
Removes comments and extra spaces while leaving strings exactly as written.
About this tool
The SQL Formatter turns messy SQL into readable, consistently indented queries. Paste a query, or open a .sql file, and the SQL is beautified at once: keywords on their own lines, clauses aligned and nested queries indented. Switch to Minify for a compact single-line version with comments and extra spaces removed.
Choose the dialect so the formatter understands your syntax. It supports 12: standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle, BigQuery, Snowflake, Redshift, Spark and Db2. You can write keywords in uppercase, lowercase or as written, and indent with 2 or 4 spaces or tabs. Several statements separated by semicolons are formatted together.
Formatting only changes whitespace, line breaks and keyword case, so your query does the same thing afterwards. It is handy for code reviews, for reading queries copied from logs or an ORM, and for keeping a team's SQL in one style. For other code, see the JSON Formatter and the CSS Formatter.
Frequently asked questions
No. Only whitespace, line breaks and the case of keywords change. String contents and identifiers are left alone.
The formatter needs valid SQL tokens. Common causes are an unclosed quote or bracket, or syntax from a different dialect. Try another dialect from the list.
Yes. Line comments and block comments are removed and extra whitespace is collapsed.
It handles many common procedural constructs, but very vendor-specific syntax may not format perfectly.
Paste your query into the box, choose the SQL dialect and press format. The result appears indented and readable, ready to copy or download as a .sql file.
Yes. Choose SQL Server in the dialect list. MySQL, PostgreSQL, Oracle, BigQuery, Snowflake and the other dialects are there too.
Yes. Set keyword case to UPPERCASE, lowercase or as written. Only keywords change, never your table names, column names or strings.