Output appears here...How to use
Paste or upload your SQL
Paste one or more statements into the Input pane, or click Upload .sql. Try sample loads a commented, lowercase SELECT with a join, GROUP BY and HAVING, all on one line.
Choose dialect and style, then Format
Pick the Dialect your database uses and set Keywords, Indent, Layout and the other options. Click Format, or turn on Live mode. Minify to one line gives compact SQL without comments.
Copy or download the SQL
Click Copy above the output or Download .sql, and paste the SQL into your editor, migration file, ticket or pull request. If you see an error, check that the dialect matches the query.
Why SQL Formatter
- Sixteen SQL dialects, from PostgreSQL and MySQL to T-SQL, BigQuery and Snowflake.
- Keyword case, indent, tabular layout and AND/OR placement options.
- Minify to one line, remove comments, and upload or download .sql files.
- Runs locally with the open-source sql-formatter library and remembers your dialect.
Formatting SQL code for different databases
Pick the dialect that matches where the query runs. The formatter then understands that database's quoting style, parameter placeholders and special keywords, which avoids errors and odd line breaks. If you are unsure, Standard SQL works for most simple SELECT, INSERT, UPDATE and DELETE statements. Switch dialects and format again if a query fails.
| Dialect option | Use it for |
|---|---|
| Standard SQL | Generic queries, or when you are not sure |
| PostgreSQL | PostgreSQL, including :: casts and $1 style parameters |
| MySQL | MySQL, with backtick-quoted names |
| MariaDB | MariaDB |
| SQLite | SQLite databases, including many mobile and desktop apps |
| SQL Server (T-SQL) | Microsoft SQL Server and Azure SQL, with [bracket] names |
| Oracle PL/SQL | Oracle Database |
| BigQuery | Google BigQuery |
| Snowflake | Snowflake data warehouses |
| Amazon Redshift | Redshift data warehouses |
| Spark SQL | Apache Spark and Databricks SQL |
| Apache Hive | Hive and HiveQL on Hadoop |
| Trino / Presto | Trino, Presto and Amazon Athena |
| SingleStoreDB | SingleStore (formerly MemSQL) |
| IBM Db2 | Db2 |
| Couchbase N1QL | Couchbase queries |
Before and after: a messy query, formatted
The sample query arrives the way many queries do, copied from a log or a BI tool as one long lowercase line: select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where ... limit 10;
After Format with the default settings, SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT each start a new line in capitals. Each selected column gets its own indented line, the LEFT JOIN sits indented under FROM with its ON condition, and the two GROUP BY columns are listed one per line. Nothing about the logic changes, but a reviewer can now see at a glance which table is joined, what is filtered and how the results are sorted. Switch Keywords to Keep as typed if your team prefers lowercase SQL.