SQL Formatter & Beautifier

Format and beautify SQL queries online. Supports MySQL, PostgreSQL, SQLite and SQL Server.

Indent:
SELECT u.id,u.name,u.email,o.total
    FROM users u
    LEFT JOIN orders o
    ON u.id=o.user_id
    WHERE u.active=1 AND o.total>100
    ORDER BY o.total DESC
    LIMIT 50;

Frequently Asked Questions

Which SQL dialects does this formatter support?

It supports standard SQL keywords and works with MySQL, PostgreSQL, SQLite, and SQL Server queries. Dialect-specific syntax is preserved as-is.

Does it validate SQL syntax?

No — it formats and beautifies the SQL structure without parsing it. Syntax validation requires a database engine.

Can I choose the indentation style?

Yes. You can choose 2 spaces, 4 spaces, or tab indentation.

Is my SQL query sent to a server?

No. All formatting runs in your browser — your queries never leave your device.

Why Format SQL Queries?

Raw SQL from ORMs, query logs, or third-party tools is often a single unbroken line — impossible to read or debug. A formatter applies consistent indentation, uppercases reserved keywords, and breaks each clause onto its own line, making the query structure immediately visible.

Formatted SQL is also easier to review in pull requests, document in wikis, and audit for performance issues such as missing JOIN conditions, implicit cross joins, or deeply nested subqueries.

SQL Clause Reference

ClausePurposeExecution order
FROMSpecify the source table(s)1
JOINCombine rows from multiple tables2
WHEREFilter rows before grouping3
GROUP BYAggregate rows into groups4
HAVINGFilter groups (post-aggregation)5
SELECTChoose columns and expressions to return6
DISTINCTRemove duplicate result rows7
ORDER BYSort the result set8
LIMITRestrict the number of returned rows9

Note: execution order determines when filters and aggregations apply — SELECT runs after WHERE, which is why you cannot reference a SELECT alias in a WHERE clause.

SQL Style Guide Conventions

  • Uppercase reserved keywords (SELECT, FROM, WHERE) to visually distinguish them from identifiers.
  • Lowercase table and column names, using snake_case as the SQL community standard.
  • One clause per line — each major clause on its own line at zero indentation; continuation lines indented by 4 spaces.
  • Use explicit JOIN syntax — always write INNER JOIN or LEFT JOIN instead of comma-separated table names (implicit cross join).
  • Alias long table names with meaningful short aliases, not single letters (o for orders), to keep queries readable after formatting.