SQL Formatter

Format SQL queries for PostgreSQL, MySQL, SQL Server, Oracle, SQLite, BigQuery and more, with keyword case options.

Runs in your browser. Nothing is uploaded.

How to use the SQL Formatter

  1. Paste one or more SQL statements into the left box, open a .sql file, or press Load example.
  2. Choose your database under Dialect so its special syntax is understood.
  3. Pick upper or lower case keywords, the indent, and where AND and OR go.
  4. The formatted SQL appears on the right. Copy it or download it as a .sql file.

Long queries you can actually read

SQL from logs, ORMs, dashboards and chat messages tends to arrive as one long line. A query with joins, a subquery and a window function becomes very hard to follow that way, and even harder to review. The formatter puts each clause on its own line, indents the columns and conditions under it, and lines up nested queries so the structure is visible at a glance.

Dialects

Databases share most of SQL but each adds its own syntax. Choosing the dialect lets the formatter understand things such as:

  • PostgreSQL :: casts, ->> JSON operators and dollar-quoted strings
  • MySQL and BigQuery backtick-quoted names
  • SQL Server [bracketed] names, TOP and GO separators
  • Oracle PL/SQL blocks and CONNECT BY
  • Snowflake, Spark and DuckDB specific functions and keywords

If you’re unsure, Standard SQL works for most everyday queries.

Style options

  • Keywords: upper case is the traditional style and makes keywords stand out; lower case is popular in modern codebases; As written keeps your own choice.
  • Indent: 2 or 4 spaces, or tabs.
  • AND / OR: at the start of the line makes long conditions easy to scan and comment out; at the end of the line is common in some teams’ style guides.
  • Compact operators writes a=b instead of a = b.

Safe to use with private queries

Production queries often reveal table names, business logic or even values. This formatter runs in your browser and never sends the SQL anywhere, so you can format sensitive queries without worrying about where they end up.

Errors

If the SQL can’t be read, the message gives the line and column of the first problem. The most common causes are an unclosed bracket or quote, a missing comma between columns, or syntax that belongs to a different dialect.

Frequently asked questions

Which databases are supported?

Standard SQL plus PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark, DuckDB, ClickHouse, Trino, Db2 and Hive. Picking the right dialect matters for things like PostgreSQL's ::casts, SQL Server's [brackets] or BigQuery's backticks.

Does formatting change what the query does?

No. Only whitespace, line breaks and the case of keywords and function names change. Table names, column names, strings and values stay exactly as written.

Why does it say it can't read my SQL?

Usually because a bracket or quote isn't closed, or the query uses syntax from a different database than the one selected. The message gives the line and column; try another dialect if the SQL is valid for your database.

Can it format several statements at once?

Yes. Statements separated by semicolons are each formatted, with a blank line between them.

Is my SQL uploaded?

No. Formatting happens in your browser, so it is safe to use with queries that contain table names or data from private systems.

Tutorials