Beautify or minify SQL queries with keyword normalization and configurable indentation. Shows byte savings percentage after minifying — copy instantly.
Structured Query Language (SQL) queries in enterprise codebases often become convoluted, poorly indented, and difficult to review. Formatting SQL statements according to consistent indentation rules and keyword capitalisation enhances readability, simplifies peer code review, and helps identify missing joins or syntax bugs.
SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY).AND and OR boolean predicates beneath the WHERE clause.| Raw Unformatted SQL | Formatted & Readable SQL |
|---|---|
select u.id,u.name,o.total from users u inner join orders o on u.id=o.user_id where o.status='completed' and o.total>100 order by o.created_at desc; | <pre>SELECT<br> u.id,<br> u.name,<br> o.total<br>FROM users u<br>INNER JOIN orders o<br> ON u.id = o.user_id<br>WHERE o.status = 'completed'<br> AND o.total > 100<br>ORDER BY o.created_at DESC;</pre> |
Different Relational Database Management Systems (RDBMS) support distinct dialects and quoting styles:
"tableName"), single quotes for string literals ('value'), :: type casting.`tableName`), custom limit syntax (LIMIT 10, 20).[tableName]), TOP keyword for limiting records.JavaScript / Node.js (sql-formatter)
import { format } from 'sql-formatter';
const unformatted = "SELECT id, name, created_at FROM customers WHERE status='active' ORDER BY name ASC";
const formatted = format(unformatted, {
language: 'postgresql',
tabWidth: 2,
keywordCase: 'upper',
linesBetweenQueries: 2,
});
console.log(formatted);
Python (sqlparse)
import sqlparse
query = "select id, name from products where price > 50 order by name"
formatted = sqlparse.format(
query,
reindent=True,
keyword_case="upper",
indent_width=2
)
print(formatted)
WITH cte_name AS (...) blocks at the top of statements with aligned column lists for modular readability.OVER (PARTITION BY ... ORDER BY ...) clauses across distinct lines for clarity.This website and utility are provided for general informational, calculation, and educational purposes only. Always verify critical computation outputs prior to professional deployment or financial use. See our Terms of Service and Privacy Policy for full governance details.