# SQL Beautifier — Format & Beautify SQL Queries Online

> Beautify SQL queries in your browser: keywords uppercased, clauses on their own lines, joins and subqueries indented — with your query never leaving the page.

Source: https://toolpantry.app/sql-formatter

## About

Turn a dense SQL query into a readable, copy-ready layout — keywords uppercased, clauses on their own lines, joins indented. Your query stays in the browser.

## Quick answer

**How do I format SQL online?** Paste a query to get readable indentation and clauses; common dialects are supported best-effort.

## What the beautifier does to your query

- **Keywords uppercased** — SELECT, FROM, JOIN, CASE/WHEN, CTEs (WITH), and window functions (OVER, PARTITION BY) get the classic uppercase treatment.
- **Clauses on their own lines** — FROM, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT each start a fresh line, so the query's structure is visible at a glance.
- **Joins and subqueries indented** — nested logic steps inward instead of flattening into one line.
- **Strings and comments preserved** — literal text inside quotes is never touched, and your -- comments survive the reformat.

## Before and after

```
-- before
select o.id, u.name, sum(oi.price*oi.qty) as total from orders o
join users u on u.id=o.user_id join order_items oi on oi.order_id=o.id
where o.created_at > '2026-01-01' and o.status in ('paid','shipped')
group by o.id, u.name having sum(oi.price*oi.qty) > 100 order by total desc limit 20;

-- after
SELECT o.id, u.name, SUM(oi.price * oi.qty) AS total
FROM orders o
JOIN users u ON u.id = o.user_id
JOIN order_items oi ON oi.order_id = o.id
WHERE o.created_at > '2026-01-01' AND o.status IN ('paid', 'shipped')
GROUP BY o.id, u.name
HAVING SUM(oi.price * oi.qty) > 100
ORDER BY total DESC
LIMIT 20;
```

## How to beautify SQL

1. **Paste your query** — long one-liners and dumps from logs are exactly the point.
2. **Format** — keywords, clauses, and nesting get normalized instantly.
3. **Copy the result** — straight into code review, a ticket, a runbook, or your editor.

## Why format SQL at all

- **Reviewing someone else's query** — a 200-character one-liner hides its joins; formatted, the mistake is usually obvious.
- **Documentation** — formatted queries in tickets and runbooks are readable months later.
- **Debugging** — missing join conditions and wrong GROUP BY scopes jump out once clauses are separated.
- **Learning** — seeing clause structure on separate lines teaches SQL faster than parsing dense text.

## Good to know

Formatting changes whitespace only — the query behaves exactly the same, but always skim your comments after any reformat. Dialects vary wildly, so this is labeled best-effort: common syntax formats identically across MySQL, PostgreSQL, SQLite, and SQL Server, while vendor-specific constructs pass through unchanged. For very large migration files, paste one statement at a time for the cleanest result. And because queries contain real table and column names, the local-only processing matters: nothing is ever sent to a server.

## Notes

This formatter changes whitespace and keyword casing only. It does not parse, validate, execute, or rewrite your SQL logic; review the result before running it.

## FAQ

**Which SQL dialects work?**

Common syntax used across MySQL, PostgreSQL, SQLite, and SQL Server — SELECT/INSERT/UPDATE/DELETE, joins, subqueries, CTEs, and window functions — formats well. Vendor-specific constructs are preserved unchanged on a best-effort basis.

**Does formatting change how the query runs?**

No — only whitespace changes. String literals are never touched and comments are preserved, so the reformatted query executes identically. Do skim your comments after reformatting, since line wrapping can move them.

**Does it support private queries?**

Yes. Formatting happens locally and the page never sends query text to a server — which matters when the query contains real table names, customer columns, or anything under NDA.

**Why is this called best effort?**

SQL dialects have vendor-specific grammar. This page formats common statements and clause structures but is not a full dialect-aware parser — unusual syntax passes through rather than breaking.

**Can I beautify a whole migration file?**

Paste one statement at a time for the cleanest result. The formatter works on any text, but very large multi-statement files are easier to review when formatted piece by piece.
