Skip to main content

SQL Formatter

Format SQL queries with dialect-aware rules for MySQL, PostgreSQL, SQLite and more.

Runs in your browser — your data never leaves your deviceFree, no sign-up
Options
Formatted SQL

The formatted SQL will appear here.

How it works

The query is tokenized by the sql-formatter library — a real, dialect-aware SQL formatter — and re-emitted with a standard layout: each column on its own line, clauses (FROM, WHERE, GROUP BY, ORDER BY) at the top level, join conditions aligned, and logical operators split onto separate lines.

Features

  • 12 SQL dialects, from MySQL to BigQuery
  • Keyword case: preserve, UPPERCASE or lowercase
  • 2 or 4 space indentation
  • Copy, download and upload actions
  • 100% client-side — nothing leaves your browser

How to use

  1. Paste your SQL query.
  2. Pick the dialect and your formatting preferences.
  3. Press Format SQL, then copy the result or download it as a .sql file.

Example

Input:  SELECT id,name FROM users WHERE active=true
Output: SELECT
          id,
          name
        FROM
          users
        WHERE
          active = true

Frequently asked questions

Which SQL dialects are supported?
Twelve: Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, T-SQL (SQL Server), PL/SQL (Oracle), BigQuery, Snowflake, DuckDB, Amazon Redshift and Apache Spark. The dialect controls tokenizer rules — things like string quoting, comments and dialect-specific keywords — so picking the right one produces the cleanest output.
Does the formatter validate my SQL?
No — it is a formatter, not a validator. It formats what it can tokenize and passes the rest through, so syntactically broken SQL may still produce output. Always test your SQL against a real database; use this tool to make queries readable, not to check they are correct.
What does the keyword case option do?
It controls the capitalization of SQL keywords like SELECT, FROM and WHERE: preserve leaves them exactly as you wrote them, while UPPERCASE and lowercase rewrite them consistently. Identifiers (table and column names) are never changed.
Will formatting change what my query does?
No. Formatting only adds whitespace and line breaks — the tokens of your query are left untouched. The formatted query is semantically identical to the input.
Is my SQL sent to a server?
No. Formatting happens entirely in your browser with JavaScript. Nothing you type is transmitted anywhere — you can verify this in your browser's network inspector.