SQL Beautifier

Input

Output

SELECT
  u.id,
  u.name,
  COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o
  ON o.user_id = u.id
WHERE u.active = true
  AND u.created_at > '2024-01-01'
GROUP BY u.id, u.name
ORDER BY order_count DESC
LIMIT 20

About the SQL Beautifier

A SQL beautifier for turning a one-line query dumped from an ORM, log, or migration into something reviewable: keywords capitalized, each clause on its own line, and AND/OR/ON conditions indented underneath. Paste a query, beautify it, and copy the result.

This is the tool for the moment a slow-query log or an ORM debug output hands you a single unreadable line of SQL and you need to actually understand what it's doing before you can optimize or debug it. Reformatting a query this way is often the fastest way to spot a missing join condition or an unintended cartesian product. It also handles a whole migration file at once — paste several semicolon-separated statements and each one is beautified in turn, with CASE/WHEN/THEN/ELSE/END expressions indented cleanly rather than left as an unreadable run-on.

How to Use the SQL Beautifier

1

Paste a SQL query into the input panel.

2

Review the beautified output — keywords capitalized and clauses broken onto their own lines.

3

Copy the result into your editor, migration, or query tool.

Frequently Asked Questions

Which SQL keywords get capitalized?

Standard clause and operator keywords — SELECT, FROM, WHERE, JOIN variants, GROUP BY, ORDER BY, HAVING, INSERT INTO, UPDATE, DELETE, AND/OR, and more — are uppercased and used to break the query onto new indented lines.

Does it touch string literals?

No. Text inside single, double, or backtick quotes is protected before formatting and restored afterward, so values like 'SELECT' inside a string are left exactly as written.

Which SQL dialect does it target?

It formats generic ANSI-style SQL common to MySQL, PostgreSQL, and SQL Server. It reformats syntax and casing rather than validating a specific dialect.

Will it validate whether my query is correct?

No — it's a formatter, not a query validator or an execution planner. It reformats syntax and casing regardless of whether the query would actually run successfully against a real database.

What indentation does it use?

Two spaces per level, fixed — there's no setting to change it. Each clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING) starts a new line, with AND/OR/ON conditions and CASE/WHEN branches indented one level under the clause they belong to.

Can I format more than one statement at a time?

Yes — paste multiple semicolon-separated statements and each is beautified independently, in order, so a migration file with several statements comes out as readable as a single query.