SQL Formatter & Beautifier
Format and minify SQL queries with 2-space, 4-space or tab indentation and uppercase, lowercase or capitalized keywords.
SQL Formatter & Beautifier
SELECT u.id,
u.name,
u.email,
COUNT(o.id) AS order_count,
SUM(o.total) AS total_spent
FROM users u
LEFT JOIN orders o
ON u.id = o.user_id
WHERE u.created_at >= '2025-01-01'
AND u.status IN('active',
'verified')
AND EXISTS
(
SELECT 1
FROM payments p
WHERE p.user_id = u.id
AND p.amount > 0
)
GROUP BY u.id,
u.name,
u.email
HAVING COUNT(o.id) > 5
ORDER BY total_spent DESC
LIMIT 50
OFFSET 10;Updated . Provided as is. Check the output before you rely on it in production.
How to use SQL Formatter & Beautifier
- 1
Paste your SQL query
Paste any SQL (SELECT, INSERT, UPDATE, DELETE, joins and subqueries). Minified or messy SQL is fine.
- 2
Read the formatted output
The query is formatted as you type: clauses start on their own lines and nested subqueries are indented further.
- 3
Set keyword case and indentation
Choose uppercase, lowercase or preserved keywords and an indent width. Formatting follows standard SQL that works across MySQL, PostgreSQL, SQLite and SQL Server.
- 4
Minify when needed
Turn on Minify to compress the query onto one line for logs or API payloads.
- 5
Copy or download
Copy the result into your database client, migration file or application code, or download it.
Questions and answers
What is SQL Formatter & Beautifier?
Does SQL Formatter & Beautifier store or send my data?
Which SQL dialects does SQL Formatter & Beautifier support?
Use it as an API
SQL Formatter & Beautifier is also callable as a free HTTP JSON API at
https://aidevhub.io/api/sql-formatter/ — GET with query
parameters or POST with a JSON body, no authentication, CORS enabled, fair use
(abusive traffic is throttled at the edge; there is no per-request quota header). Responses return
{ ok, tool, result, meta }.
curl -s -X POST https://aidevhub.io/api/sql-formatter/ \
-H "Content-Type: application/json" \
-d '{"sql":"select id, name from users where active = 1 order by name","mode":"format"}' Machine-readable contract: /api/tool/sql-formatter.json All API endpoints: /agents/ LLM site index: /llms.txt
For AI agents: how to call this tool
Machine-readable contract, endpoints and examples. Humans can ignore this section.
Best Path For Builders
Dedicated API endpoint
Deterministic outputs, machine-safe contracts, and production-ready examples.
Dedicated API
https://aidevhub.io/api/sql-formatter/ OpenAPI: https://aidevhub.io/api/openapi.yaml