SQL Formatter & Beautifier

Paste a query to tidy it up: clauses on their own lines, consistent indentation and keyword case, subqueries and CASE expressions laid out clearly. Or minify it onto one line. Works with PostgreSQL, MySQL, SQL Server, SQLite, BigQuery and Oracle.

Input

    Output

    
          

    What this SQL formatter does

    SQL copied from logs, ORMs and query builders usually arrives on one long line. This tool rewrites it in a consistent, readable layout without changing what the query does: every keyword, name, string and number stays exactly as it was, only the spacing, line breaks and (if you choose) keyword case change. Formatting happens as you type, entirely in your browser, so queries with real table names or customer data never leave your machine.

    The formatter follows the most common style: each clause (SELECT, FROM, WHERE, GROUP BY…) starts a new line, the items inside it are indented below, joins line up under FROM, AND/OR conditions get a line each, and subqueries and CTEs are indented inside their brackets. Short brackets such as COUNT(*) or IN (1, 2, 3) stay on one line.

    SELECT
      c.name,
      COUNT(o.id) AS orders
    FROM
      customers c
      LEFT JOIN orders o ON o.customer_id = c.id
    WHERE
      c.active = TRUE
      AND o.created_at >= '2026-01-01'
    GROUP BY
      c.name
    ORDER BY
      orders DESC
    LIMIT 10;

    Options

    OptionWhat it changes
    DialectHow quotes, comments and parameters are read: `backticks` and # comments in MySQL and BigQuery, [brackets] in SQL Server and SQLite, $$dollar-quoted$$ function bodies and E'…' strings in PostgreSQL, backslash escapes in MySQL strings.
    KeywordsUPPERCASE (the classic convention), lowercase (popular in modern codebases) or exactly as you wrote them. Only keywords, built-in functions and data types change; table and column names are never touched.
    Layout“One item per line” puts every column and table on its own line, which gives the cleanest diffs in code review. “Compact” keeps a clause's items on the keyword's line, like SELECT id, name.
    CommasTrailing commas (a,) or leading commas (, a). Leading commas make it easy to comment out the last column.
    Keep on one lineBrackets whose content fits in the chosen width stay on one line, such as IN ('a', 'b') or OVER (PARTITION BY x); longer ones are expanded with one item per line.

    Minify

    Minify puts the whole query on one line with single spaces, which is handy for embedding SQL in code, config files or a log search. Comments are removed unless you tick “Keep comments” (optimizer hints such as /*+ INDEX(t idx) */ and MySQL /*! … */ comments are always kept, because they change how the query runs).

    Problems it points out

    The formatter is not a full SQL parser, so it won't tell you that a column doesn't exist, but it does catch the mistakes that most often break a pasted query: a string or quoted name that is never closed, an unclosed /* comment, and brackets that don't match. Each problem shows its line and column; click it to jump there in the input.

    Tips for readable SQL