SQL Formatter

Format SQL queries with proper indentation, uppercase keywords, and line breaks at clause boundaries. Supports Standard SQL, PostgreSQL, MySQL, MariaDB, T-SQL, PL/SQL, BigQuery, and Snowflake dialects. Runs entirely in your browser.

How to use the SQL Formatter

Paste SQL, pick the dialect (use Standard if unsure), and click Format. The output places each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING) on its own line, indents subqueries, and aligns column lists. Minify produces a single-line version for embedding in code.

Why formatting SQL matters

Unformatted SQL is hard to read in code review and harder to debug. A 200-character single-line query hides errors that a properly-indented version makes obvious. Common patterns where formatting saves time: missing comma in a column list, mismatched parentheses in nested subqueries, wrong join order, accidental Cartesian product from a forgotten ON clause.

Dialect matters because SQL implementations diverge in subtle ways. PostgreSQL accepts DISTINCT ON; MySQL doesn't. T-SQL uses TOP instead of LIMIT. BigQuery requires backticks around fully-qualified table names. Picking the right dialect makes the formatter preserve and align dialect-specific keywords correctly.