SQL Formatter

Overview

The SQL formatter re-indents and restructures SQL queries into readable code, supporting 19 database dialects. Paste a compressed or poorly formatted query, choose the dialect, and the formatted output appears instantly. Keyword casing, indentation style, and line-break positions are all configurable.

Choosing the right dialect

Picking the wrong dialect does not break your SQL, but it does affect formatting accuracy. Key differences:

MySQL / MariaDB

  • Backtick identifiers (`table`) are recognized correctly
  • MySQL-specific functions like GROUP_CONCAT are handled without misinterpretation
  • AUTO_INCREMENT and ENGINE=InnoDB clauses are not flagged as errors

PostgreSQL

  • Double-quoted identifiers ("table") treated as the standard
  • RETURNING and ON CONFLICT DO UPDATE format correctly
  • Array operators && and @> are not misread as arithmetic

For SQL Server, prefer transactsql over the generic sql option — it handles TOP, WITH(NOLOCK), and other T-SQL-specific syntax more accurately. BigQuery users should select the BigQuery dialect explicitly when queries include backtick-delimited project paths.

Formatting before and after

SELECT * FROM users WHERE age > 18 AND status='active' OR role IN ('admin','moderator') ORDER BY created_at DESC LIMIT 10

Formatted with standard indent style:

SELECT
  *
FROM
  users
WHERE
  age > 18
  AND status = 'active'
  OR role IN ('admin', 'moderator')
ORDER BY
  created_at DESC
LIMIT
  10

Indent style and expression width

Three indent styles are available: standard (clauses aligned left), tabular-left (keywords right-aligned, columns vertically aligned), and tabular-right (keywords left-aligned, columns compact). The expression width setting (default 50 characters) controls when parenthesized expressions wrap. Lower it when you want each item in an IN (...) list on its own line — useful for SQL diffs in code review.

AND / OR line-break placement

By default, AND and OR start the next line (leading style). If your team's convention is to put them at the end of the previous line, switch the "Logical operator line break" option to "after". The number of blank lines between multiple statements can be set to 1 or 2 for separating batch scripts.

All formatting runs locally in the browser; no SQL is uploaded to any server.