Skip to content
AZ Tools

SQL Formatter

Format and beautify SQL across 10 dialects (PostgreSQL, MySQL, BigQuery, Snowflake, T-SQL …).

Formatted

How to use

  1. Paste the SQL into the input.
  2. Pick the dialect (default Standard SQL works for most queries).
  3. Choose keyword case and indent width.
  4. Copy the formatted output.

About this tool

Show

Paste any SQL — a one-liner pulled out of a log, a hand-written query, a procedure from a stack trace — and see it pretty-printed with consistent indentation, your choice of keyword casing, and blank lines between statements. Picking the dialect matters more than it looks: PostgreSQL, MySQL, BigQuery, Snowflake, T-SQL and the rest disagree about quoting, window syntax, returning clauses and which words are reserved, and choosing the wrong one is what produces oddly broken output. This is a formatter and not a parser, so it will lay out a query that would never run; it tells you nothing about whether the SQL is valid, and nothing is ever executed. No SQL leaves the page.

Frequently asked questions

Which dialects are supported?

Standard SQL, PostgreSQL, MySQL, SQLite, MariaDB, T-SQL (SQL Server), BigQuery, Snowflake, Redshift, and Spark SQL — provided by the sql-formatter library.

Does it execute the query?

No — it only reformats text. The query is never run, parsed against a real database, or sent anywhere.

Will it break on syntax errors?

It's resilient — the formatter does its best on partially valid SQL and shows an error message only when it cannot read the structure at all, such as an unclosed string or unbalanced parentheses.

Why are comments preserved oddly?

SQL comments don't have a strict canonical position. The formatter keeps them attached to the nearest token, which sometimes shifts indentation a little.

The output looks mangled. What did I get wrong?

Usually the dialect. Each one disagrees about quoting, reserved words and its own syntax extensions, so formatting T-SQL as PostgreSQL breaks brackets and formatting MySQL as standard SQL breaks backtick identifiers. Switch the dialect to the database the query is actually written for before assuming the query is at fault.

Does a clean format mean the query is valid?

No, and that is worth internalising. This lays out text; it does not parse SQL for correctness or check that a table exists. A query with a missing join condition or a typo in a column name formats just as neatly as a correct one — the database is still the only thing that can tell you it works.

Related tools