SQL Beautifier

Reformat unruly SQL into readable queries

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

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.

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.