SQL Formatter & Beautifier
Format and beautify SQL queries online. Supports MySQL, PostgreSQL, SQLite and SQL Server.
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
| Clause | Purpose | Execution order |
|---|---|---|
| FROM | Specify the source table(s) | 1 |
| JOIN | Combine rows from multiple tables | 2 |
| WHERE | Filter rows before grouping | 3 |
| GROUP BY | Aggregate rows into groups | 4 |
| HAVING | Filter groups (post-aggregation) | 5 |
| SELECT | Choose columns and expressions to return | 6 |
| DISTINCT | Remove duplicate result rows | 7 |
| ORDER BY | Sort the result set | 8 |
| LIMIT | Restrict the number of returned rows | 9 |
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_caseas 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 JOINorLEFT JOINinstead of comma-separated table names (implicit cross join). - Alias long table names with meaningful short aliases, not single letters (
ofororders), to keep queries readable after formatting.