Skip to content

SQL formatter: beautify queries for any dialect, free, in your browser

A SQL formatter rewrites a query with consistent indentation, one clause per line and uppercased keywords so that long SELECT statements with joins and subqueries are readable. Formatting does not change what the query does. This tool formats locally in your browser, supports the major dialects (PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, BigQuery, Snowflake, Spark, Hive, Trino, DB2, PL/SQL), and can minify as well.

C11SQL formatter — TabbyTools
Ready0 B sent to server

Your files never leave your device. Processing happens in your browser. How that works.

How it works

  1. Paste your SQL.
  2. Pick a dialect, keyword case and indent.
  3. Copy the formatted query.

Runs as JavaScript inside this tab. Turn off your connection after the page loads and it still works.

SQL style reference

What the formatter does

  • One clause per line: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.
  • Select-list items, join conditions and AND/OR predicates on their own indented lines.
  • Sub-queries and CTEs indented one level per nesting.
  • Keywords uppercased (or lowercased, or left alone). Identifiers, strings and comments are never changed.
  • Multiple statements separated by a blank line.

Formatting never changes semantics. If a query fails to parse, pick the dialect that matches its syntax; the parser is strict about dialect-specific features such as TOP, backtick quoting or :: casts.

Dialect differences

Feature PostgreSQL MySQL / MariaDB SQL Server SQLite BigQuery
Identifier quoting "name" `name` [name] or "name" "name" or [name] `project.dataset.table`
String concatenation || CONCAT() + || || or CONCAT()
Cast ::type or CAST() CAST() CAST() / CONVERT() CAST() CAST() / SAFE_CAST()
Limit LIMIT n OFFSET m LIMIT m, n TOP n / OFFSET … FETCH LIMIT n OFFSET m LIMIT n OFFSET m
Case-insensitive match ILIKE LIKE (collation) LIKE (collation) LIKE LOWER()
Boolean TRUE/FALSE 1/0 1/0 (BIT) 1/0 TRUE/FALSE
Upsert ON CONFLICT ON DUPLICATE KEY MERGE ON CONFLICT MERGE

Conventions worth adopting

  1. Keywords upper, identifiers lower with snake_case: SELECT user_id FROM orders.
  2. Leading commas or trailing commas, but not both in one codebase. Trailing (a,\n b) is the default here.
  3. Explicit JOIN … ON, never comma joins with the condition in WHERE.
  4. Alias every table in multi-table queries and qualify every column.
  5. CTEs (WITH) over nested sub-queries once nesting passes two levels.
  6. Uppercase AS for column aliases; omit it for table aliases if your team prefers.
  7. Never SELECT * in application code; list columns so schema changes do not break callers.

Indent styles

  • Standard: clauses at column 0, items indented by the indent width.
  • Tabular left: keywords right-padded so items align in a column (SELECT id).
  • Tabular right: keywords right-aligned ( SELECT id / FROM t), the classic “river” style.

Minify

Minify strips comments and collapses whitespace outside string literals and quoted identifiers, which is safe for any dialect. It does not shorten identifiers or rewrite the query.

Worked examples

A join with grouping

Input (one line): select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id, u.name order by orders desc limit 10;

SELECT
  u.id,
  u.name,
  COUNT(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.active = 1
GROUP BY
  u.id,
  u.name
ORDER BY
  orders DESC
LIMIT
  10;

A CTE with a window function

WITH
  ranked AS (
    SELECT
      id,
      customer_id,
      total,
      ROW_NUMBER() OVER (
        PARTITION BY
          customer_id
        ORDER BY
          total DESC
      ) AS rn
    FROM
      orders
  )
SELECT
  *
FROM
  ranked
WHERE
  rn <= 3;

Dialect matters

SELECT TOP 5 * FROM t parses under SQL Server but fails under PostgreSQL, which expects LIMIT 5. SELECT price::numeric FROM t needs PostgreSQL.

Minify turns the formatted join back into a single line, dropping any -- comments, ready for a log line or a URL parameter.

Frequently asked questions

Does formatting change the query result?

No. Only whitespace and keyword case change. String literals and identifiers are left exactly as written.

Why choose a dialect?

Dialects differ in keywords, quoting and operators (for example BigQuery backticks or T-SQL brackets). Picking the right one avoids mis-formatting.

Can it format stored procedures?

Basic procedural blocks are supported for PL/SQL and T-SQL, but complex control flow may not be indented perfectly.

Is my query sent anywhere?

No. Formatting runs in your browser.

SQL formatter · last updated · changelog · part of Canned Tuna